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

Using criteria-api to dynamic tables

I use criteria-api to made sql query to the database and it work very fine. But now I need to use dynamic tables , where some tables can be create or destroyed and some column can be add or removed. I want to manage this entityties in dynamicBean…
Troncador
  • 3,356
  • 3
  • 23
  • 40
0
votes
1 answer

How to make it in JPA Criteria?

Supposing I have entity Lecturer and Course two entities having many to many relationships in JPA 2.0 It is perfectly OK to have a non-annotated entity LecturerCourse (with multi-table selection columns, not annotated) and JPQL like this working. …
Korben
  • 734
  • 1
  • 7
  • 26
0
votes
0 answers

hibernate Criteria API many to many

TaskCategory.hbm.xml
avinash chavan
  • 729
  • 2
  • 11
  • 27
0
votes
1 answer

Criteria Query with multiple cascaded joins involved

I have three entities: Block, Viewand TargetBlockand want to create a JPA Criteria query for the following sql. select * from Block INNER JOIN TargetBlock tb ON tb.blockID = b.blockID INNER JOIN view v ON tb.viewID = v.viewID Block has many views…
user942309
  • 61
  • 1
  • 1
  • 6
0
votes
2 answers

CriteriaAPI get collection size

I have got two entities: first Person (table person); @Entity public class Person implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) private Integer id; …
Piotr Sobolewski
  • 2,024
  • 4
  • 28
  • 42
0
votes
1 answer

JPA Criteria api query fails while JPQL goes through

I'm using JPA to manage my persistency layer. One of my my Criteria API throws an exception. I re-wrote it in JPQL and it works just fine so I guess I missed something in my criteria api version. Here it is, my criteria api query: public…
forhas
  • 11,551
  • 21
  • 77
  • 111
0
votes
1 answer

Writing a NON-EXIST query using JPA / Criteria

I'm running an application simulates selling air plane tickets. Using a simple schema (1-n): SEAT ------ id_seat description position BOOKING --------- id customer id_seat I'd like to produce a Query using either JPA API or Criteria which…
Max Korn
  • 275
  • 7
  • 18
0
votes
1 answer

JPA : How to write query function

I know from sample code how to write one query function like findAll(): javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return…
stackover
  • 122
  • 1
  • 7
0
votes
1 answer

JPA criteria API: How to use IN keyword and query the result for another predicate?

Sorry for the bad title, I don't really know how to word it better: I have the following tablestructure: Table A --> Table B <-- Table C (proceeds) --> Table D(prcoeeding_status) -------- -------- ------- ------- aID …
random_error
  • 365
  • 4
  • 16
0
votes
2 answers

fetch required property using Criteria API?

I have customer and customerAddress class. CustomerAddress class have country n state object.When I load customer i want CustomerAddress also and in customerAddress i want to load only contryName and countryID other details must be null. In short…
Amogh
  • 4,453
  • 11
  • 45
  • 106
0
votes
2 answers

Criteria eclipselink join

I can't understand how do a join in eclipse link with criteria. This my entity: public class A implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private Long…
Terence
  • 69
  • 1
  • 11
0
votes
2 answers

How can the criteria api add quote to the column?

In my aplication I use eclipselink and the criteria api. My database have a table with a column called "order". The problem is when I use the criteria api to create a select it made this sql: SELECT id, order, name, phone, uri FROM campus It throw…
Troncador
  • 3,356
  • 3
  • 23
  • 40
0
votes
1 answer

Fetch persons with specific authorities - spring security with grails

I have typical Spring Security domain class layout (Person, Authority and join table PersonAuthority). I made following query, but I don't know how to build properly criteria for fetching persons that have only specific authorities (last 'if'…
Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
0
votes
1 answer

Query with JPA criteria API

Tried building this query but I guess I'm missing something. Here are the involved classes: User Diet DailyDiet Here are the relevant parts of my entities (A pretty simple one): public class User { @Column(name = "User_Name", nullable = false,…
forhas
  • 11,551
  • 21
  • 77
  • 111
0
votes
1 answer

jpa criteria seems to work (or not) depending on whether db is mysql or objectdb

When I use JPA with MySQL, the below query works fine. But when I use it with ObjectDB, it throws the exception below. public Friendship getFriendship(String username) { CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); …
kasavbere
  • 5,873
  • 14
  • 49
  • 72
1 2 3
99
100