Date: Wed, 07 Sep 2011 15:15:36 +0200 From: Lele User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.java.help Subject: CriteriaQuery and JPA Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: $$afwhll$slnyo.news.x-privat.org Message-ID: <4e676e7b$1@news.x-privat.org> Organization: X-Privat.Org NNTP Server - http://www.x-privat.org Lines: 54 X-Authenticated-User: $$p9zou1n1$ng5dhdq$s2 X-Complaints-To: abuse@x-privat.org Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!newsfeed.x-privat.org!x-privat.org!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:1020 Hi. I'm trying to make some examples of query using CriteriaQuery. For now i'm trying to do something like that: @Entity @Table(name = "USERS") public class ClassTest { public ClassTrueAuth(){ this.username = "test"; } @Id @Column(name="testfield") public boolean testField ; @Column(name="username") public String username; } and inside my code: ClassTest cta = new ClassTest(); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery cq = criteriaBuilder.createQuery(ClassTest.class); Root from = cq.from(ClassTest.class); cq.select(from); Predicate p = criteriaBuilder.equal(from.get(cta.username),"test"); cq.where(p); TypedQuery q = entityManager.createQuery(cq); List result = q.getResultList(); This give to me a NullPointerException... How to check if a string field is equal to a constant? I tried to make another field in TestClass: @Column(name="test") public String test = "test"; and retry the same code above. The query string printed in console is: select classtest0_.testfield as testfield35_, classtest0_.username as username35_, classtest0_.test as test36_ from USERS classtruea0_ where classtruea0_.test=? and 'result' is empty... Why where clause is test=? instead of username=test ? Please help me! Thank you so much!