NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

J2EE6 Criteria builder

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
smoczyna



Joined: 08 Jan 2009
Posts: 34

PostPosted: Wed Jun 30, 2010 8:11 am    Post subject: J2EE6 Criteria builder Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo