Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7673
| Date | Wed, 07 Sep 2011 14:58:40 +0200 |
|---|---|
| From | Lele <lamia@mail.lcom> |
| 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.programmer |
| 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 | <4e676a82$2@news.x-privat.org> (permalink) |
| 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!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.straub-nv.de!newsfeed.x-privat.org!x-privat.org!not-for-mail |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7673 |
Show key headers only | View raw
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<ClassTest> from = cq.from(ClassTest.class);
cq.select(from);
Predicate p = criteriaBuilder.equal(from.get(cta.username),"test");
cq.where(p);
TypedQuery<ClassTest> q = entityManager.createQuery(cq);
List<ClassTest> 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!
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar
CriteriaQuery and JPA Lele <lamia@mail.lcom> - 2011-09-07 14:58 +0200 Re: CriteriaQuery and JPA Lew <lewbloch@gmail.com> - 2011-09-07 11:04 -0700
csiph-web