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

jpa - transforming jpql join query to criteria api

I was trying to transform this JPQL query; SELECT s FROM QuestionSet s JOIN s.questions q WHERE q.appointedRepetition.date < :tomorrow to its criteria api equivalent, here is what I have so far: DateTime tomorrow =…
Andna
  • 6,539
  • 13
  • 71
  • 120
0
votes
1 answer

dynamic criteria query multiple selection

I want to write a totally dynamic query method, which gets dinamically column names as parameters. Column names i.e : id, age, name, etc. I'm going to use criteria query, however I don't know how it's done exactly. Some example says: "Path
SzGyD
  • 88
  • 7
0
votes
1 answer

Making query with Criteria API

I'm introducing with Criteria API and I have a problem with making queries, I'm trying to do this for 2 days so I need your help. I have to get US zip codes from database, but as United States have cities with the same name in many states and…
0
votes
0 answers

JPA CriteriaBuilder: Predicate with a Serializable field throws an exception

I have an entity with a persistent field declared as Serializable. I would like to build a query with the CriteriaBuilder, that filters the results by the Serializable field. The database is Oracle, and the field type is RAW(255) as hbm2ddl defined…
Istvan
  • 17
  • 1
  • 5
0
votes
1 answer

Hibernate criteria for compare SUM of three columns againts another column

I have a table with columns as ID, col1, col2, col3, col4, col5. I want to add a hibernate criteria restriction as (col1 + col2 + col3) < col4 All these columns contains integer values. How could I achieve this requirement ? Any help appreciated.
SAP
  • 468
  • 2
  • 14
0
votes
1 answer

JPA Query with openJPA only works as 'native' SQL, but it does not when transformed as JPQL or with JPA Criteria

I have a SQL query and the mapping of the classes. Using openJPA, if the query is made as a @NamedNativeQuery it works fine, returning the correspondent class and the expected result. If it is transformed into a JPQL @NamedQuery it always returns a…
azl
  • 109
  • 1
  • 8
0
votes
3 answers

JOIN 3 Entities in JPA

This is the first time I develop an Java application and immediately face an issue. Now I have a SQL query as below: Select PD.* From product PD join Stock SP on PD.id = SP.product_id join storage SR on SR.id = SP.storage_id join status ST on…
Phong Vo
  • 1,078
  • 7
  • 16
0
votes
1 answer

JPA subquery generates ID twices in SQL query

I have a problem doing a composite select using JPA CriteriaQuery . I have three tables X->Y->Z , for every X I have one or more Y and for every Y I have one or more Z. I have an X object and I am trying to select all the occurrences of Z for one…
Nicolae Birlea
  • 113
  • 1
  • 1
  • 5
0
votes
1 answer

Group Criteria API query's results by the day part of a date

In Criteria API i have to group the results of a query based on the day part of a date column returned in the query. Can you please suggest how to do this? The following is the multiselect query cq.multiselect(root.get("id"), root.get("recievedOn"))…
Aneeque
  • 99
  • 1
  • 9
0
votes
3 answers

Select records which doesn't have specific records in joined table

Hi I'm trying to select records from one table which doesn't have records in connected many-to-many table with specific values. I will explain on sample…
J33nn
  • 3,034
  • 5
  • 30
  • 46
0
votes
1 answer

Getting a JPA Criteria Query to work with an inherited list

Say I have an entity @Entity public class Test { @ManyToMany @JoinTable(..etc..) private List subjects; // School subjects this test is associated with .... And an entity @Entity public class Exam extends Test { // Inherits…
DCKing
  • 4,253
  • 2
  • 28
  • 43
0
votes
1 answer

Project an Entity from a relationship with Hibernate Criteria

I'm having trouble getting a list of related entity objects as the result of a criteria expression. I have two objects with a many to many relationship such that ObjectA <-> ObjectB where a single instance of ObjectA can be tied to a multiple…
Clayton
  • 5,330
  • 1
  • 18
  • 15
0
votes
1 answer

Criteria API join a lazy Collection

I have the following setup @Entity @Table(name = "Product") public class Product implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String name; @OneToMany(cascade =…
Stefan
  • 63
  • 1
  • 2
  • 8
0
votes
1 answer

JPQL equivalent

I have to write an JPQL query for the following Oracle-SQL: SELECT * FROM Foo f, Bar b, Xyz x WHERE f.id = b.foo(+) and f.id = x.foo(+) and (lower(f.label) like lower('%filter%') or lower(f.code) like lower('%filter%') or lower(b.label) like…
witchi
  • 345
  • 3
  • 16
0
votes
2 answers

How to fetch data using example object in JPA 2

I'm using Hibernate 3.5.6 and JPA 2. Here is my code: public List searchRoutesEndingAt(GeoLocation destinationLocation, int destinationRangeInMeters, RouteUserPref routeUserPref) { Query query =…
sumitarora
  • 580
  • 4
  • 18
1 2 3
99
100