Hibernate find by criteria get single result

Posted by GigaPr on Stack Overflow See other posts from Stack Overflow or by GigaPr
Published on 2010-04-22T13:57:50Z Indexed on 2010/04/22 14:23 UTC
Read the original article Hit count: 172

Filed under:
|

Hi,

i am experimenting using Hibernate.

I am trying to get a User by id this is what i do

public User get(DetachedCriteria dc){
    List<User> users = getHibernateTemplate().findByCriteria(dc);
    if(users != null)
    {
        return users.get(0);
    }
    else return null;
}

but it fails when the user is not in the database. Could you help me to understand how to achieve this?

Thanks

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about findbycriteria