Questions tagged [jpa-2.0]

This tag is for questions about the version 2.0 of the Java Persistence API. The focus of JPA 2.0 was to address features that were present in some of the popular ORM vendors but could not gain consensus approval for JPA 1.0.

The is latest major specification for .

Main features included in this update are:

  1. Expanded object-relational mapping functionality
  2. Criteria query API
  3. Standardization of additional metadata to support DDL generation
  4. Support for validation

Vendors supporting JPA 2.0

JPA 2.0 Wiki information

3218 questions
144
votes
6 answers

In JPA 2, using a CriteriaQuery, how to count results

I am rather new to JPA 2 and it's CriteriaBuilder / CriteriaQuery API: CriteriaQuery javadoc CriteriaQuery in the Java EE 6 tutorial I would like to count the results of a CriteriaQuery without actually retrieving them. Is that possible, I did not…
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
143
votes
11 answers

JPA CascadeType.ALL does not delete orphans

I am having trouble deleting orphan nodes using JPA with the following mapping @OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "owner") private List bikes; I am having the issue of the orphaned roles hanging around…
Paul Whelan
  • 16,574
  • 12
  • 50
  • 83
131
votes
5 answers

How can I validate two or more fields in combination?

I'm using JPA 2.0/Hibernate validation to validate my models. I now have a situation where the combination of two fields has to be validated: public class MyModel { public Integer getValue1() { //... } public String getValue2()…
Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
126
votes
7 answers

JPA: unidirectional many-to-one and cascading delete

Say I have a unidirectional @ManyToOne relationship like the following: @Entity public class Parent implements Serializable { @Id @GeneratedValue private long id; } @Entity public class Child implements Serializable { @Id …
perp
  • 3,883
  • 4
  • 31
  • 29
113
votes
2 answers

Storing a Map using JPA

I am wondering if it is possible using annotations to persist the attributes map in the following class using JPA2 public class Example { long id; // .... Map attributes = new HashMap(); // .... } As…
corydoras
  • 7,130
  • 12
  • 55
  • 58
83
votes
1 answer

How to define unidirectional OneToMany relationship in JPA

I have a following problem with entity mapping in JPA. I have two entities, first one is Lookup and the second is Text which represents translations for entities. Now I need to bound Lookup to the Text but I don't want Text to have reference to…
Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
80
votes
2 answers

org.hibernate.QueryException: illegal attempt to dereference collection

I am trying following hql query to execute SELECT count(*) FROM BillDetails as bd WHERE bd.billProductSet.product.id = 1002 AND bd.client.id = 1 But it is showing org.hibernate.QueryException: illegal attempt to dereference…
xrcwrn
  • 5,339
  • 17
  • 68
  • 129
79
votes
6 answers

Which Java Type do you use for JPA collections and why?

Which of the following collection types do you use in your JPA domain model and why: java.util.Collection java.util.List java.util.Set I was wondering whether there are some ground rules for this. UPDATE I know the difference between a Set and a…
Theo
  • 3,074
  • 7
  • 39
  • 54
72
votes
2 answers

What to use: JPQL or Criteria API?

My Java application is using JPA for object persistence. The business domain is very simple (just three classes are persistent, with 3-5 properties in each). Queries are simple as well. The question is which approach I should use: JPQL or Criteria…
yegor256
  • 102,010
  • 123
  • 446
  • 597
72
votes
15 answers

java.lang.IllegalStateException: Multiple representations of the same entity with @ManyToMany 3 entities

I have 3 entities with ManyToMany relationships: Role Entity: @Entity public class Role { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer roleID; private String roleName; private String description; …
user1188867
  • 3,726
  • 5
  • 43
  • 69
72
votes
1 answer

What is the purpose of AccessType.FIELD, AccessType.PROPERTY and @Access

I just want to know what is the difference between all these annotations. Why are we using these... means they have no effect especially field level and property level. And what is the purpose of using mixed level annotation…
Ashish Bansal
  • 904
  • 1
  • 9
  • 11
69
votes
4 answers

JPA Criteria Tutorial

I've been trying to find a JPA Criteria API tutorial but haven't been much successful. Do you know about any for beginners? I'd like to start using it in an Java5/Maven app to build complex search queries.
John Manak
  • 13,328
  • 29
  • 78
  • 119
67
votes
3 answers

How to properly express JPQL "join fetch" with "where" clause as JPA 2 CriteriaQuery?

Consider the following JPQL query: SELECT foo FROM Foo foo INNER JOIN FETCH foo.bar bar WHERE bar.baz = :baz I'm trying to translate this into a Criteria query. This is as far as I have gotten: CriteriaBuilder cb =…
chris
  • 2,541
  • 1
  • 23
  • 40
67
votes
4 answers

JPA Hibernate many-to-many cascading

I am using JPA 2.0 and hibernate. I have a User class and a Group class as follows: public class User implements Serializable { @Id @Column(name="USER_ID") private String userId; @ManyToMany @JoinTable(name = "USER_GROUP", …
Hery
  • 7,443
  • 9
  • 36
  • 41
66
votes
4 answers

JPA 2.0, Criteria API, Subqueries, In Expressions

I have tried to write a query statement with a subquery and an IN expression for many times. But I have never succeeded. I always get the exception, " Syntax error near keyword 'IN' ", the query statement was build like this, SELECT t0.ID,…
Keating
  • 3,380
  • 10
  • 34
  • 42
1
2 3
99 100