NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
smoczyna
Joined: 08 Jan 2009 Posts: 34
|
Posted: Wed Jun 30, 2010 8:11 am Post subject: J2EE6 Criteria builder |
|
|
I'm smoking up J2EE6 persistence and have a problem with criteria building. Following code returns more that 1 result. Could anybody explain why? there should be only 1 record.
| Code: | public StaticCode findAddressTypeByType(String addressType) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<StaticCode> cq = cb.createQuery(StaticCode.class);
Root<StaticCode> staticCodes = cq.from(StaticCode.class);
cq.where(cb.equal(staticCodes.get("type"), "address_type"));
cb.and(cb.equal(staticCodes.get("code"), addressType));
Query q = em.createQuery(cq);
return (StaticCode) q.getSingleResult();
} |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|