Questions tagged [criteriaquery]

245 questions
1
vote
1 answer

Cast to subclass when joining with the base class using CriteriaBuilder (OpenJPA)

I have a simple hierarchy TradeCustomer is an OrganisationRole. An OrganisationRole is linked to Organisations. Organisation has a property roles containing all roles of an organisation. I'd like to write a JPA query using the CriteriaBuilder which…
Leukipp
  • 550
  • 2
  • 9
  • 25
1
vote
2 answers

How to generate "select count(*) ..." using CriteriaQuery

I wrote the following code to get the count of "ExampleEntity": cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Long.class); root = cq.from(ExampleEntity); cq.select(cb.count(root)); return…
vduk225
  • 31
  • 6
1
vote
1 answer

query all row in table that is link from another table using query builder

I have a table that have few rows of variable. One of this row link to another table that have more rows. To put it clear, 1 table is called Connection. The variable is: name, groupname, etc. The groupname should link to a second table called…
Mohd Fikrie
  • 197
  • 4
  • 21
1
vote
1 answer

How do I write a JPA query to populate a data transfer object (different than my @Entity object)?

We’re using Java 6, JPA 2.1, and Hibernate 4.3.6.Final. I have the below code that finds our Organization objects … final CriteriaBuilder builder = entityManager.getCriteriaBuilder(); final CriteriaQuery criteria =…
Dave
  • 15,639
  • 133
  • 442
  • 830
1
vote
1 answer

JPA 2.1 CriteriaQuery between Date

How can I use CriteriaQuery with BETWEEN clause in Date? I have tried this without success; the DAO method: public List listRegistry(Date init){ List registrys = null; try{ Date currentDate = new Date(); …
G Bisconcini
  • 764
  • 2
  • 6
  • 25
1
vote
1 answer

JPA Criteria Query with IN operator for Set with Spring DATA-JPA

In my application, I have the following mapping between two entities : @Entity public class Applicant { private Integer id; .... private Set documents; ... Getters and Setters ... @OneToMany(fetch =…
Kevin Davin
  • 144
  • 1
  • 5
1
vote
1 answer

how to extend jpa order

I search table with Criteria Query and filter it with name field. i filter records that have name like %user-entered-name%. then sort result with name column. now i have a problem. i will it sort like following: name (First list records that his…
Rasoul Taheri
  • 802
  • 3
  • 16
  • 32
1
vote
0 answers

JPA save CriteriaQuery

After creating a JPA CriteriaQuery, we need to keep it so that we can refine search later or for pagination. In hibernate, we used DetachedCriteria that is not associated with EntityManager. But JPA CriteriaQuery is created from EntityManager. The…
Dave
  • 487
  • 1
  • 6
  • 19
1
vote
1 answer

Difference between CriteriaBuilder and CriteriaQuery for a Collection

What is the difference between: criteriaBuilder.in(predicate); criteriaQuery.where(predicate); This seems to give the same results. Am I missing something? Should we choose the builder above the query? Complete example: List names = new…
Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127
1
vote
1 answer

JPA CriteriaQuery: getCount + condition

I try to get all the count of Articles (Article.class) which are not analyzed (analyzed == false). Sadly the following code returns absolutely wrong numbers. Would anybody know why? CriteriaBuilder cb =…
Johannes Rabauer
  • 330
  • 3
  • 15
1
vote
1 answer

JPA criteria query + self join on rowid

I'm trying to write JPA criteria query. Select * from classA t1 inner join (SELECT rowid FROM classA where conditions... ORDER BY clause )t2 on t1.rowid = t2.rowid ORDER BY clause where rownum <= 500 I'm having…
Amit Yatagiri
  • 425
  • 1
  • 4
  • 16
1
vote
1 answer

Selecting all kind of entities from a table but limiting to a member of a derived entity

I have an entity structure like this: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="CLASS_TYPE", discriminatorType= DiscriminatorType.STRING) @DiscriminatorValue(value="SUPER") public class SuperEntity…
Hennes
  • 1,340
  • 1
  • 10
  • 26
1
vote
0 answers

SQL as JPA2. How to create a CriteriaQuery in JPA2 with MAX(), GROUP BY, ORDER BY, LIMIT and FOUND_ROWS()

In MySQL I'm able to select MAX value for desired column, group and order records, limit result and get total rows count in two SQL statements (executions): SELECT SQL_CALC_FOUND_ROWS b.class, b.age FROM ( SELECT students.*, max(age) FROM…
Jason P
  • 11
  • 3
1
vote
1 answer

EclipseLink Criteria API count in results after joining table

After ours of searching I was still unable to find a way to write this SQL equivalent in EclipseLink criteria query: SELECT preke.*, count(nuotrauka.prid) AS cnt FROM preke LEFT JOIN nuotrauka ON nuotrauka.prid=preke.prid WHERE trash = 1 GROUP BY…
Minutis
  • 1,193
  • 1
  • 17
  • 47
1
vote
2 answers

Are begin() and commit() required for JPA CriteriaQuery?

I have a simple question to ask regarding JPA's CriteriaQuery-based queries? I noticed in the Java EE examples (http://docs.oracle.com/javaee/6/tutorial/doc/giqsq.html) that entityManager.getTransaction().begin() and…
Some Newbie
  • 1,059
  • 3
  • 14
  • 33