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
6
votes
3 answers

InvalidDataAccessApiUsageException: Parameter value [...] did not match expected type [java.util.UUID (n/a)]

I'm using Criteria API to build named queries using filters. It works on normal String comparisons but when filtering on UUID it throws the following error: org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value…
Edito
  • 3,030
  • 13
  • 35
  • 67
6
votes
1 answer

JPA Criteria API - Add days to DATE using ORACLE

I'm trying to use JPA Criteria API to filter a date between a specific range. The problem is that I don't have directly the date in my entity, I obtain the date using a date field and adding a number of days (which are in another field) to this…
albciff
  • 18,112
  • 4
  • 64
  • 89
6
votes
0 answers

Using Entity Graph with DTO Projection using ResultTransformer returns null value

Hello I am new in jpa + criteria API + hibernate.. I have doubt related to use of ResultTransformer in jpa criteria API. I am having two entity Department and Employee. one to many mapping between department and employee. i want to use entitygraph…
6
votes
2 answers

Spring Data Specification for set contains operation

I have two entities, A and B. There is many-to-many relationship between them, where A hold a list of B. How to write a Specification to retrieve all A entites that contains B with specific name? Example: @Service public class YourService { …
VB_
  • 45,112
  • 42
  • 145
  • 293
6
votes
1 answer

hibernate how to show the criteria queries

I think this is a simple question although I do not know how to solve it. In a spring/Hibernate application I need to show the query that a criteria execute. I know that I can use show_sql property and log the queries using log4j or any other…
Fanooos
  • 2,718
  • 5
  • 31
  • 55
6
votes
2 answers

How can I express joining to a grouped subquery using NHibernate?

I'm trying to express a SQL query using NHibernate's Criteria API, and I'm running into difficulty because I'm thinking in a database-centric way while NHibernate is object-centric. SQL (works great): select outerT.id, outerT.col1, outerT.col2,…
David Rubin
  • 1,610
  • 1
  • 17
  • 28
6
votes
4 answers

Search by nested property of collection field with criteria api

I'm trying to find all entities that have some nested elements and nested elemens have collections of elements, and I need to find it by property of those collections. It would be something like this class A{ private B b; } class B{ private…
Nadir
  • 1,369
  • 1
  • 15
  • 28
6
votes
1 answer

JPA CriteriaDelete with huge parameters

I am using JPA 2.1, Oracle DB and have a list of ids for entities to be removed (about 430000 ids). At first, it was implemented as splitting that id list into each smaller one with 1000 ids, pass them as parameters for a JPQL and executing. delete…
pirent
  • 83
  • 6
6
votes
3 answers

Using @ElementCollection in CriteriaQuery (or Querying over the content of an @ElementCollection)

public enum ReportStatus { SUCCCEED, FAILED; } public class Work { @ElementCollection @Enumerated(EnumType.STRING) List reportStatuses; } Given the following structure, I'd like to perform a query to find all the…
Raphaël Brugier
  • 480
  • 5
  • 14
6
votes
1 answer

Complex querying with NHibernate

I have this problem: When I try to implement Ayende's complex searching found at: http://ayende.com/Blog/archive/2006/12/07/ComplexSearchingQueryingWithNHibernate.aspx with the object graph: Person: M:1 Address: …
Luka
  • 4,075
  • 3
  • 35
  • 61
6
votes
4 answers

Why the compiler doesn't recognize the metamodel attributes?

Is the criteria api of eclipselink jpa2 supported for java se 6 projects? If not, that's my problem. Do I need to specify anything special to the criteria api in the persistence.xml? This is my criteria query: final EntityType Meaning_ =…
simpatico
  • 10,709
  • 20
  • 81
  • 126
6
votes
1 answer

Criteria API and Entity Graph

I have two entities with unidirectional lazy relations. And one of them has a named entity graph. Here are the entities (getters and setter are not listed due to readability): @Entity @NamedEntityGraph ( name = "Sms.fetchSims", …
Wyvie
  • 140
  • 1
  • 6
6
votes
3 answers

JPA reading data with NO LOCK

In the application we're writing, it is required that we use the with(NOLOCK) in our queries. Just so that the queries don't take so long to process. I haven't found anything on how to accomplish this. What I did find is how to enable optimistic or…
Erates
  • 646
  • 1
  • 9
  • 24
6
votes
1 answer

Using an @Embeddable entity in a JPA CriteriaQuery

Let's say I have the following example entities - one is an @Embeddable, embedded inside another @Entity: @Embeddable public class ContactInfoEntity { @Column private String phone; @Column private String…
metacubed
  • 7,031
  • 6
  • 36
  • 65
6
votes
2 answers

Is it possible to define LEFT Join when annotating a relationship with @OneToMany?

I have the following scenario @Entity public class Parent { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; @Column(name = "name", nullable = false) private String name; …
rodrigoArantes
  • 354
  • 1
  • 4
  • 13