0

I'm trying to use LocalDate and LocalDateTime with Java 8 in my app. I'm using Hibernate 4.3.5 and Spring. I followed this interesting tutorial here and all works but I've a problem when I use DATE() construct.

When I try to do:

SELECT * FROM TABLE 
WHERE DATE(data)=DATE(:data)

I get an IllegalArgumentException because setParameter is expecting java.util.Date instead of java.time.LocalDate, if I don't use DATE() construction it is expecting java.time.LocalDateTime, I already implemented hibernate converters but I can't find a good solution for it (converting from LocalDate to java.util.Date doesn't look for me good), anyone knows how fix this problem?

Ankit Popli
  • 2,809
  • 3
  • 37
  • 61
roman-v1
  • 728
  • 1
  • 9
  • 21
  • Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); (http://stackoverflow.com/questions/22929237/convert-java-time-localdate-into-java-util-date-type). First match of google search – Lajos Arpad Jun 23 '15 at 16:19
  • converting from LocalDate to java.util.Date doesn't look for me good, I already wrote it in my question, I'm interested why I can't use LocalDate in this place. – roman-v1 Jun 23 '15 at 16:20
  • "doesn't look for me good" can mean a lot of things. Did you mean it is not good? If so, why? – Lajos Arpad Jun 23 '15 at 16:37
  • Because hibernate know that I want use LocalDateTime when I use full date with time, but it still trying use java.util.date when I just want compare dates. – roman-v1 Jun 23 '15 at 16:55

0 Answers0