Is it possible to select data with max value for a column using Criteria in Hibernate?

Posted by Palo on Stack Overflow See other posts from Stack Overflow or by Palo
Published on 2010-03-19T15:58:22Z Indexed on 2010/03/19 16:01 UTC
Read the original article Hit count: 160

Filed under:
|
|

Lets say I have the following mapping:

<hibernate-mapping package="mypackage">
    <class name="User" table="user">
  <id name="id" column="id">
   <generator class="native"></generator>
  </id>        
  <property name="name" />
  <property name="age" />
  </class>
</hibernate-mapping>

Is it possible to select the oldest user (that is age is maximal) using Criteria in Hibernate?

I can imagine that i could do this with 2 selects. (first select total number of users and then order the entries descending by age and select the first entry). But is it possible with a single select?

Thank you

Palo

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about query