Skip to content
Advertisement

How to create hibernate request with localdate

I have a user who has an expiration date (dateTime), I need to display all users who have not expired yet. Tried different options with DATA (), or as an example –

JavaScript

but it doesn’t output anything. But when asked in MySQL – SELECT * FROM user where user.date> NOW () displays everything as it should. Tell me how to implement this query in Hibernate?

Advertisement

Answer

Replace annotation attribute “name” with “value“:

JavaScript

The annotation attribute “name” always refers to a named query, while the attribute “value” can be used to specify a query. “value=” can be omitted, so this works too:

JavaScript

See https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query for details.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement