This is the query to how to get the max string value from a table.
Option 1
Use max function inside the DBMS.
Double max = (Double) sess.createSQLQuery("select max(cat.weight) as maxWeight from cats cat where extLicenseID < '5000-0000' ")
.addScalar("extLicenseID", Hibernate.STRING);
.uniqueResult();
Option 2
Use setMaxResults of the hibernate and addOrder of asc or desc.
List cats = sess.createCriteria(Cat.class)
.add( Property.forName("name").like("F%") )
.addOrder( Property.forName("name").asc() )
.addOrder( Property.forName("age").desc() )
.setMaxResults(50)
.list();
Tony
No comments:
Post a Comment