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

CriteriaBuilder haven't got a method createCriteriaUpdate

I need bulk update some entities using JPA 2.1. Here: http://wiki.eclipse.org/EclipseLink/Release/2.5/JPA21#Update_Example I found example how to do it. If I wrtite: CriteriaUpdate orderRecordEntity It's ok. But when I…
0
votes
1 answer

how to create query in Criteria api

I have a class: @Entity public class Resume { private Long id; @Embedded private DesiredPositionAndSalary desiredPositionAndSalary; } and class: @Embeddable public class DesiredPositionAndSalary { @ManyToMany private…
Pasha
  • 642
  • 6
  • 22
0
votes
1 answer

JPA: m=Multiple criterias using entity Manager (OR clause)

I am using JPA's(Entity Manager) Criteria query to fetch results from database. I need to put 'OR' clause between the criterias. My code is as below: List criteraList = new ArrayList(); if(user.getEid() != null){ …
Heena Ghai
  • 63
  • 1
  • 3
0
votes
1 answer

Is it possible to implement an exists query based on @ElementCollection using Jpa criteria query?

I'm learning Jpa criteria query and have no idea of how to implement this: I have an entity called Restaurant: @Entity @Table(name = "t_f2g_restaurant", uniqueConstraints = @UniqueConstraint(columnNames = { "NAME" })) public class Restaurant { …
Yugang Zhou
  • 7,123
  • 6
  • 32
  • 60
0
votes
1 answer

Criteria API Conditionally Evaluate 'NULL'

I have the following Criteria API query used to evaluate a given value against a number of Subject attributes. ... Expression literal = builder.literal((String) "%" + filterValue + "%"); // When the globalFilter is deleted it returns "" …
tarka
  • 5,289
  • 10
  • 51
  • 75
0
votes
1 answer

Sql query to be converted into HQL or Criteria

Below is the sql query which will fetch the results which is a combination of many inner joins..and the corresponding pojos are Table JAVA POJO boopUSER User booprtyu rtyu user.java contains the following…
user2644736
0
votes
1 answer

How do I insert a native Oracle call or cast (to NVARCHAR2) in a criteria api expression?

I have a complex dynamic query in Eclipselink with a case expression that involves two different columns, one of VARCHAR2 and one of NVARCHAR2. It needs to be a case expression, because I also want to be able to sort by that result column, so I…
user2633841
0
votes
1 answer

Using Hibernate Criteria API To Query Many-To-One Relationships with Projections

I am trying to use Criteria API in following scenario: I have two tables, Schedule and Route (with their classes and mappings). Route has many-to-one relationship with Schedule. Route has an integer property sequence. Now I need to fetch all those…
craftsman
  • 15,133
  • 17
  • 70
  • 86
0
votes
1 answer

How to do it with JPA Criteria API?

How can I do Criteria Query in JPA2, which is equivalent to this JPQL with and without using metamodel? SELECT p FROM Employee e JOIN e.phones p WHERE e=:empl
srnjak
  • 915
  • 7
  • 21
0
votes
1 answer

Criteria Builder Select Object_

EntityManager em; em = this.getEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Date.class); Root newsRoot =…
Carlo Adap
  • 69
  • 1
  • 11
0
votes
1 answer

hibernate: left outer join with Criteria API, is possible?

I'm new on Hibernate so excuse me for banality but I can't find any answer related to my problem (i tried to search on docs & on SO). If possible, I would create a left outer join from two tables (t0 and t1) without using HQL; in my case I'd like to…
mrddter
  • 59
  • 8
0
votes
1 answer

JPA/Hibernate Criteria API JOIN

I have a problem with join in CriteriaAPI. I want to get the result with unique Forma entities, but currently I get multiple entities (their number is equal to the number of Gniazdo entities). This is my code: CriteriaBuilder cb =…
bemol
  • 381
  • 3
  • 18
0
votes
1 answer

JPA Criteria ManyToMany Join or No Join?

i have 2 Entities with the following Metamodels. @StaticMetamodel(SearchIn.class) public class SearchIn_ { public static volatile SingularAttribute id; public static volatile SingularAttribute
Dennis Ich
  • 3,585
  • 6
  • 27
  • 44
0
votes
1 answer

JPA Modelgen generates model classes but does not compile them

We are using JPA 2, Hibernate and the Criteria API in our project for which we need the Model Generator of Hibernate to create meta model classes. In our Ant build process we included the annotation processor of hibernate-jpamodelgen.jar to generate…
Tom
  • 3,913
  • 19
  • 28
0
votes
1 answer

Customize JPA CriteriaQuery's on-clause

Is there a way to further restrict a join by adding some expressions? With plain sql i write: SELECT c.*, COUNT(i.id) invoice_count FROM customers c LEFT JOIN invoices i ON i.customer_id = c.id AND i.creation_time >= '2012-01-01' -- <= extra…
mazatwork
  • 1,275
  • 1
  • 13
  • 20