Questions tagged [criteria-api]

This tag is for questions related to the Java Persistence Criteria API (from JPA 2.0) which is used to define queries through the construction of object-based query definition objects, rather than use of the string-based approach of the Java Persistence query language. For questions related to (N)Hibernate Criteria, use the [icriteria] tag.

Quoting the Overview from the JPA 2.0 Specification:

6.1 Overview

The Java Persistence Criteria API, like the Java Persistence query language is based on the abstract persistence schema of entities, their embedded objects, and their relationships as its data model. This abstract persistence schema is materialized in the form of metamodel objects over which the Criteria API operates. The semantics of criteria queries are designed to reflect those of Java Persistence query language queries.

The syntax of the Criteria API is designed to allow the construction of an object-based query “graph”, whose nodes correspond to the semantic query elements.

Java language variables can be used to reference individual nodes in a criteria query object as it is constructed and/or modified. Such variables, when used to refer to the entities and embeddable types that constitute the query domain, play a role analogous to that of the identification variables of the Java Persistence query language.

These concepts are further described in the sections that follow. The metamodel on which criteria queries are based is presented in Chapter 5. The static metamodel classes that can be used in constructing strongly-typed criteria queries are described in section 6.2. The javax.persistence.criteria interfaces are presented in Section 6.3. Sections 6.4 through 6.8 describe the construction and modification of criteria query objects. Additional requirements on the persistence provider are described in section 6.9.

1541 questions
0
votes
1 answer

NHibernate: How to exclude a class which is part of a join using the Criteria API

I am still new to Hibernate and am attempting to use it for a web site I have inherited. Unfortunately that means sometimes the db schemas don't always make sense. With that said, I am trying to build the following HQL query using the Criteria…
rmblstrp
  • 254
  • 3
  • 10
0
votes
0 answers

Perform query and record count using CriteriaBuilder

I populating a Primefaces datatable lazily with a custom complex dynamic query built using CriteriaBuilder, performing a SQL query on a database. For that I need to perform a record count using this query and I also need to run the query itself to…
Jitesh Pramodray
  • 424
  • 1
  • 7
  • 16
0
votes
1 answer

Exception in getting list from CriteriaQuery

for some reason i can't tell, there is exception when i try to get a list from CriteriaQuery using subquery. some one please help!!! here is the code: public String[] getProductsDistinctBySubQueriesName(String category) { CriteriaBuilder builder…
Abiodun Osinaike
  • 155
  • 1
  • 4
  • 14
0
votes
0 answers

JPA Criteria query to setRowCount

I am new in JPA, I have try to make Dynamic query with Criteria Query. my code : CriteriaBuilder cb = crudService.getEm().getCriteriaBuilder(); // query 1 CriteriaQuery cq = cb.createQuery(MsCountry.class); Root
0
votes
3 answers

SQL/Criteria Query CONTAINS ALL?

Table A: Table A_B: Table B: id | a a_id | b_id id | b ------ ----------- ------ 1 | w 1 | 1 1 | s 2 | x 1 | 2 2 | t 3 | y 2 | 4 3 …
Benjamin M
  • 23,599
  • 32
  • 121
  • 201
0
votes
1 answer

use NamedQuery or Criteria API

I have a complex query e.g. search employees with name, age, address, etc I would like to append a WHERE clause if a parameter IS NOT NULL. for example (pseudo code): if (age != null) // then append age to the where clause whereClause +=…
0
votes
2 answers

Will Hibernate always generate one SQL for one HQL?

It is often better to execute two simpler SQL queries than one functionally identical complex SQL query. Does Hibernate ever tries to use this optimalization for HQL (or Criterias or whatever) or does it always generate just one SQL? You may ask,…
qbd
  • 533
  • 1
  • 6
  • 18
0
votes
2 answers

not allowed truncated value in group by [criteria API]?

I have a query like : select name, trunc( date, 'MM' ), sum( number ) from t$mytable group by name, trunc( date, 'MM' ); which runs perfectly, and gives expected result. I implemented exactly the same query in JPA criteria API : CriteriaBuilder…
SzGyD
  • 88
  • 7
0
votes
0 answers

Java - JPA 2 CriteriaBuilder construct - inner/nested class

I have a standard SQL query that is used to create a class Project. Project also contains class ProjectParticipant. That same query fetches all data for both Project and ProjectParticipant, So first I create new ProjectParticipant() all fill the…
0
votes
1 answer

Am trying to compare String with BigDecimal in openjpa using Criteria builder

list.add(build.equal(bondRoot.get(Bond_.writingCompanyCode),dtlRoot.get(ArPstdDtl_.companycd ).as(String.class))); but am getting the following error: Caused by: org.apache.openjpa.persistence.ArgumentException: No metadata was found for type…
0
votes
2 answers

How to calculate the size of Criteria query result set for hibernate?

How to calculate the size in bytes (not number rows) of the resultset returned by a criteria query? We receive a Out of Memory Exception and on analysis of heapdump we found the org.hibernate.impl.sessionimpl object is the most bloated object. We…
Siva VG
  • 45
  • 1
  • 9
0
votes
1 answer

get max value of composite column using jpa criteria query

want to get the maximum value of composite column relationId from table ElementRelationType I have written code which is only working for non composite key. my compositKey contains relationId and language CriteriaBuilder cb1 =…
Surya
  • 416
  • 4
  • 7
  • 26
0
votes
1 answer

Dealing with polymorphic classes in Criteria API

For a search feature i have to implement a quite join heavy query to return all location based services from specified ranges (PLZAreaRange). As you can see there are a lot of inheritance structures till i reach the PLZAreaRange to compare the…
mkuff
  • 1,620
  • 6
  • 27
  • 39
0
votes
1 answer

How to create dynamic query using criteriaquery for many-to-one

I have Person as one to many relationship with Address in JPA . @Id @Column(name="personid") private Long personId; private String firstName; private String lastName; private String email; @OneToMany(cascade =…
Achyut
  • 377
  • 1
  • 3
  • 17
0
votes
1 answer

JPA2 CriteriaBuilder: Using LOB property for greaterThan comparison

My application is using SQLServer and JPA2 in the backend. App makes use of a timestamp column (in the SQLServer sense, which is equivalent to row version see here) per entity to keep track of freshly modified entities. NB SQLServer stores this…
dev
  • 1,648
  • 16
  • 25