Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1020
| Date | 2011-09-07 15:15 +0200 |
|---|---|
| From | Lele <lamia@mail.lcom> |
| Newsgroups | comp.lang.java.help |
| Subject | CriteriaQuery and JPA |
| Message-ID | <4e676e7b$1@news.x-privat.org> (permalink) |
| Organization | X-Privat.Org NNTP Server - http://www.x-privat.org |
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.help | Previous | Next — Next in thread | Find similar
CriteriaQuery and JPA Lele <lamia@mail.lcom> - 2011-09-07 15:15 +0200
Re: CriteriaQuery and JPA Lew <lewbloch@gmail.com> - 2011-09-07 11:02 -0700
Re: CriteriaQuery and JPA Lele <lele@lele.com> - 2011-09-08 09:48 +0200
Re: CriteriaQuery and JPA Lele <lelel@lele.com> - 2011-09-08 15:03 +0200
Re: CriteriaQuery and JPA markspace <-@.> - 2011-09-08 06:39 -0700
Re: CriteriaQuery and JPA Lele <lelel@lele.com> - 2011-09-08 16:53 +0200
Re: CriteriaQuery and JPA Lew <lewbloch@gmail.com> - 2011-09-08 09:05 -0700
csiph-web