It is not a "problem" as you stated it.
Hibernate has the built-in find()
, but you have to build your own query in order to get a particular object. I recommend using Hibernate's Criteria
:
Criteria criteria = session.createCriteria(YourClass.class);
YourObject yourObject = criteria.add(Restrictions.eq("yourField", yourFieldValue))
.uniqueResult();
This will create a criteria
on your current class, adding the restriction that the column "yourField" is equal to the value yourFieldValue
. uniqueResult()
tells it to bring a unique result. If more objects match, you should retrive a list.
List<YourObject> list = criteria.add(Restrictions.eq("yourField", yourFieldValue)).list();
If you have any further questions, please feel free to ask. Hope this helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…