I am trying to fetch the record from table where highest age + the name
Criteria criteria = session
.createCriteria(Person.class)
.setProjection(Projections.max("age"));
Integer maxAge = (Integer)criteria.uniqueResult();
This above code gives me the highest age in the whole table , Whereas i want to get the highest age only where person name = “john”
how can i achieve this ?
I tried to add a critera afterwards in this way
Criteria critNew = session
.createCriteria(Person.class);
critNew.add(Restrictions.eq("personName","john"));
critNew.add(Restrictions.eq("age", maxAge));
but with this way it will only search for john where maxAge is “the highest age in the whole table”
for example if maxAge in the whole table is 50.
and there are 3 person with the name “john” with ages “10”, “20” , “30”
My Code will not work
Please suggest
Thanks
Just put together into one criteria.