jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
206 stars 59 forks source link

current LocalTime, LocalDate, and LocalDateTime in queries #317

Closed gavinking closed 2 years ago

gavinking commented 3 years ago

Currently the JPA spec defines current_date, current_time, and current_timestamp, which have been interpreted by implementations to be of type java.sql.Date, java.sql.time, and java.sql.Timestamp respectively (even though it seems that the JPA spec leaves this unspecified!).

The problem is that java.sql.Date, java.sql.time, and java.sql.Timestamp are essentially deprecated and replaced by the types in java.time.

Hibernate 6 supports the syntax

I prefer the versions without the underscores because they look more consistent with the rest of the language, which doesn't use underscores anywhere (e.g. we don't write order_by or inner_join, nor do we write alias.created_time to refer to a field of an entity).

I believe that similar functionality should be added to the JPA spec.

An alternative approach would be to introduce some sort of setting which changed the interpretation of the existing syntax current_date, current_time, and current_timestamp, but I think this option is inferior.

Thoughts?

m-reza-rahman commented 3 years ago

This looks like a good, sound enhancement that dovetails nicely with what is happening in Java SE. I hope it makes it into the next specification revision.

gavinking commented 3 years ago

(Note that as a subtask of this issue, we would clarify the types of datetime expressions.)

beikov commented 3 years ago

Sounds good to me!