Non empty list with null elements returned from Hibernate query

I'm new to hibernation, so not sure if this is the expected behavior, anyway:

Session session = (Session)entityManager.getDelegate();
Criteria criteria = session.createCriteria(myRequest.class);
criteria.add(Restrictions.eq("username", username));
criteria.setProjection(Projections.max("accesscount"));
List<myRequest> results = criteria.list();

      

The returned results are a non-empty list with only one null element.

I can't think of any reason why it should behave this way, any idea if this is the expected behavior or if I did something wrong?

The system is in sleep / Syabse.

Thanks.

+2


a source to share


1 answer


It is only surprising if there was a user with that username that had a nonzero n in the accesscount column. Does your return type make it believe that you were trying to get the myRequest instance with the maximum access? that's not what this request does. Request is equivalent

select max(m.accesscount) from myRequest m where m.username = :username

      



It just (tries to) return a number, not myRequest.

+3


a source







All Articles