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
2 answers

How I can convert a special select from sql statement into criteria API

Today I have a problem with my existing sql statement. I want need to use it with TomEE (Tomcat+Java EE) and written in criteria down. I have these selects in my sql: SELECT dest.zc_zip as zip, dest.zc_location_name as locname, ACOS( …
Lyçann H.
  • 113
  • 1
  • 5
  • 15
0
votes
1 answer

How to convert SQL Query using CriteriaQuery in JPA

I want to convert my sql query from SQL to Criterias (i dont want to use JPQL), i have this sql query: SELECT * FROM ( SELECT CONCAT_WS(' ',p.first_name, p.middle_name, p.last_name) AS fullname FROM persons p) AS tmp WHERE fullname LIKE '%cetina…
maxtorzito
  • 308
  • 7
  • 14
0
votes
1 answer

Criteria API/HQL for this entity class

I have the following entity class: @Entity @Table(name = "auditrecord", uniqueConstraints = { @UniqueConstraint(columnNames = { "accountid", "repositoryid" }) }) public class AuditRecordEntity { private UUID accountId; private UUID…
user2586917
  • 762
  • 1
  • 9
  • 26
0
votes
1 answer

JPA Criteria builder for logical operator OR

I need to prepare a query some thing like below dynamically, I am getting group column in a different list and main column in a different list, Can some one help me? SELECT * FROM TABLE WHERE COLUMN_A =1 ? OR (COLUMN_B='A' AND…
user3157090
  • 517
  • 3
  • 12
  • 29
0
votes
1 answer

Hibernate criteria implementation for this entity model (subquery, self-join)

Given the following entity one-to-many model: One Repository can be linked to many AuditRecords. Many AuditRecords can all link to the same Repository @Entity class AuditRecordEntity { private AuditRepositoryEntity auditRepository; …
user2586917
  • 762
  • 1
  • 9
  • 26
0
votes
1 answer

Select columns from join table only without requiring a join

Given these tables: create table Orders ( Id INT IDENTITY NOT NULL, primary key (Id) ) create table Items ( Id INT IDENTITY NOT NULL, primary key (Id) ) create table OrdersItems ( OrderId INT not null, ItemId INT not null, …
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
0
votes
2 answers

Convert this HQL to Criteria

I have the following HQL statement: select auditRecord from AuditRecordEntity auditRecord where auditRecord.auditAccount.accountId = :accountId I'd like to convert it to use the javax.persistence.criteria.CriteriaBuilder, but am unsure what do do,…
user2586917
  • 762
  • 1
  • 9
  • 26
0
votes
2 answers

Equations in "order by" using jpql or criteria api

Let's assume mySweetTable has 2 columns X and Z. How would I achieve this using jpql or criteria API ? SELECT *, (3 * X + Z) AS OrderCondition FROM mySweetTable WHERE U LIKE "as%" or V LIKE "as%" ORDER BY OrderCondition DESC
0
votes
1 answer

Simple Criteria query - Select From IN

I have table Events | EVENT_ID | OTHER | ---------------------------- | | | | | | | | | and table EventCategories that contains foreign key for Event table: | …
0
votes
1 answer

JPA Criteria Build how to use Order By Clause with ASC NULLS FIRST

How can I use the "order by" clause with "asc nulls first"? This is my code: CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(MyClassModel.class); //esprToOrder is a Expression istance…
bancomat
  • 15
  • 6
0
votes
1 answer

Criteria API root.join operation. What happen?

I have an entity Provider and each provider has list of ProviderLanguage @OneToMany(fetch = FetchType.EAGER) @JoinColumn(name = PROVIDER_ID, referencedColumnName = PROVIDER_ID) private Set providerLanguages; A part of providers…
Volodymyr Kozubal
  • 1,320
  • 1
  • 12
  • 16
0
votes
0 answers

GORM criteria request

Writing request that fetches all document entities that match different criteria I have two requests that work and each of them return some results that are completely different: First: def documents = Document.withCriteria { …
Nikita
  • 194
  • 3
  • 10
0
votes
1 answer

Hibernate Criteria : Find property nested in a list

Im trying to build using CriteriaBuilder the following query : SELECT * FROM job j, asset a, asset_users au where j.JOB_ID = a.ASSET_ID and a.ASSET_ID = au.ASSET_ID and au.USER_ID = 6 Where job has an asset and asset has a list of users... I…
TW.
  • 27
  • 1
  • 12
0
votes
1 answer

How to use mysql's "use index()" clause in hibernate criteria?

I am using criteria API in my project but the query which is created from hibernate is very slow. When I run the explain on the query I found that the required index is not being used. So I tried to use "use index()" clause provided by MYSQL and the…
Priyank
  • 1
  • 1
  • 5
0
votes
3 answers

Add SQL condition to CriteriaQuery

I need add something like Restrictions.sqlRestriction to CriteriaQuery. How to add SQL condition to CriteriaQuery? My code: CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery criteriaQuery =…
Akvel
  • 924
  • 1
  • 15
  • 32