Reputation: 1160
I have a query Select * from uploadedFile where uid="tesetetesdsfjdsfj";
I want to write this query in jpa and i have tried this
CriteriaQuery<UploadedFile> query = em.getCriteriaBuilder().createQuery(UploadedFile.class);
Root<UploadedFile> product = query.from(UploadedFile.class);
return em.createQuery(query)
.setFirstResult(0) // offset
.setMaxResults(10) // limit
.getResultList();
And i dont know how add where condition in this query (where uid="tesetetesdsfjdsfj";
)
Upvotes: 2
Views: 503
Reputation: 1994
Can be achieved with following snippet:
Query query = entityManager.getCriteriaBuilder().createQuery("from UploadedFile fm where sm.someField=:arg1");
query.setParameter("arg1", arg1);
Upvotes: 1
Reputation: 7998
Can be achieved with following snippet:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<UploadedFile> cq = cb.createQuery(UploadedFile.class);
Root<UploadedFile> product = cq.from(UploadedFile.class);
cq.select(product);
cq.where(cb.equal(
// you can replace product.get(UploadedFile_.uid) with product.get("uid")
product.get(UploadedFile_.uid), "tesetetesdsfjdsfj"));
em.createQuery(cq)
.setFirstResult(0)
.setMaxResults(10)
.getResultList();
More info on using the API can be found here
Upvotes: 1