7
votes

I wonder how to use date literals in Hibernate query language. I did as follows in my JPA project (as Eclipselink the provider) and it works.

SELECT m FROM Me m WHERE m.dob <= {d '1984-10-06'}

But this does not work when I change Hibernate (V 3.6.7) as the provider for my JPA project.

1
What you quote there is valid JPA syntax (see JPA2 spec section 4.6.1 - "JDBC escape syntax"). If Hibernate doesn't support it then its a bug in Hibernate, and should be raised as that. - DataNucleus
@DataNucleus I agree with you. According to Hibernate's promise to support JPA, they must support this syntax. But Hibernate seems to support the date literal as 'yyyy-mm-dd' instead of {d 'yyyy-mm-dd'} - siva636
We are using Hibernate V3.6.8 in a project and this valid JPA syntax doesn't work neither. - Stephan

1 Answers

3
votes

The reference documentation says:

Expressions used in the where clause include the following:
[...]

  • SQL literals 'foo', 69, 6.66E+2, '1970-01-01 10:00:01.0'