HQL - find the object where property x is the highest

Can I execute HQL queries?

"get a UserEntity where the creationTimestamp property is the last of all UserEntities."

Essentially a request to return the “newest user” to our program, where each UserEntity has a field mapped to a timestamp column in our database.

+3
source share
3 answers

HQL query for a list of users from the newest:

from UserEntities
order by creationTimestamp desc

Use to restrict the result set to only one user. setMaxResults

+4
source

The query for the highest value of creationTimestamp will look like this:

from UserEntity where creationTimestamp = max(creationTimestamp)

( ) , query.uniqueResult().

. 14. HQL: .

+7
0
source

Source: https://habr.com/ru/post/1751664/


All Articles