Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from Jadira 7.0.0.CR1 to Java 17 #121

Open
rcbandit111 opened this issue Feb 9, 2023 · 3 comments
Open

Migrate from Jadira 7.0.0.CR1 to Java 17 #121

rcbandit111 opened this issue Feb 9, 2023 · 3 comments

Comments

@rcbandit111
Copy link

rcbandit111 commented Feb 9, 2023

I use 'org.jadira.usertype:usertype.core:7.0.0.CR1' into my project. I want to migrate to Java 17. I have the following columns definitions:

  @Column(name = "update_date")
  @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
  private DateTime requestDate;

Do you know how I can replace the code for latest Java 17/Hibernate/Spring Boot?

@rcbandit111 rcbandit111 changed the title Migrate from Jadire 7.0.0.CR1 to Java 17 Migrate from Jadira 7.0.0.CR1 to Java 17 Feb 9, 2023
@theigl
Copy link

theigl commented Feb 9, 2023

it looks like this project has been abandoned.

I recently finished migrating my project to Hibernate 6. You have a couple of options:

  1. Use java.time.OffsetDateTime instead of DateTime
  2. Write your own custom type for DateTime

Something like this:

public class DateTimeJavaType extends AbstractClassJavaType<DateTime> {

	public static final DateTimeJavaType INSTANCE = new DateTimeJavaType();

	public DateTimeJavaType() {
		super(DateTime.class, ImmutableMutabilityPlan.INSTANCE);
	}

	@Override
	public <X> X unwrap(DateTime value, Class<X> type, WrapperOptions options) {
		if (value == null) {
			return null;
		}
		if (DateTime.class.isAssignableFrom(type)) {
			return (X) value;
		}
		if (Timestamp.class.isAssignableFrom(type)) {
			return (X) new Timestamp(value.toDate().getTime());
		}
		throw unknownUnwrap(type);
	}

	@Override
	public <X> DateTime wrap(X value, WrapperOptions options) {
		if (value == null) {
			return null;
		}
		if (value instanceof Timestamp) {
			return new DateTime(value);
		}
		if (value instanceof DateTime) {
			return (DateTime) value;
		}
		throw unknownWrap(value.getClass());
	}
	
	@Override
	public JdbcType getRecommendedJdbcType(JdbcTypeIndicators indicators) {
		return indicators.getTypeConfiguration()
				.getJdbcTypeRegistry()
				.getDescriptor(Types.TIMESTAMP);
	}
}

Then you can use it like this:

  @JavaType(DateTimeJavaType.class)
  private DateTime until;

@rcbandit111
Copy link
Author

@theigl Thanks for the reply. Using java.time.OffsetDateTime looks good enough. Any issues that I might face?

@yili001
Copy link

yili001 commented Mar 6, 2023

I have the similar problem, but it's about currency mapping:

@Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount")
private Money fee;

anyone gets any idea to work around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants