0

I'd like to use the hibernate criteria api on my Order entity in the following way:

Restrictions.eq("orderDate", new org.joda.time.DateTime());

However my Order entity uses the Java 8 time api:

class Order {
    java.time.ZonedDateTime orderDate;
}

With the code as it stands Hibernate tries to cast the joda DateTime to the java ZonedDateTime, which inevitably fails.

I was wondering if anyone knows of a way to inform hibernate how to convert any occurrences of DateTime to ZonedDateTime without having to make a change to the Restrictions.eq call?

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
James
  • 1,720
  • 5
  • 29
  • 50
  • Why are you mixing JodaTime and Java 8 DataTime API? That doesn't make sense – Simon Martinelli May 23 '19 at 10:44
  • I think OP got old API and now he tries to migrate that to Java8 and dont want to refactor billions of Restiction entries - guess. But still, I would drop joda and use Java8 time API – Antoniossss May 23 '19 at 10:45
  • Maybe this will help https://stackoverflow.com/a/34612650/1527544 – Antoniossss May 23 '19 at 10:46
  • @Antoniossss Yes that's exactly right, I'm currently migrating away from joda and there's a huge amount of work to refactor all Restrictions. Thanks for the suggestion of `hibernate-java8`, I've just had a look in to it and unfortunately that was for hibernate <5.2 before it supported java 8 in `hibernate-core` and therefore not related to joda – James May 23 '19 at 11:24

0 Answers0