In JPA (Hibernate), when we automatically generate the ID field, it is assumed that the user has no knowledge about this key. So, when obtaining the entity, user would query
This solution is from Beginning Hibernate book:
Query query = session.createQuery("from User u where u.scn=:scn", User.class); query.setParameter("scn", scn); User user = query.uniqueResult();