Questions tagged [jpa]

The Jakarta Persistence API (formerly Java Persistence API) (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. JPA was defined as part of the EJB 3.0 specification as a replacement for the EJB 2 CMP Entity Beans specification. JPA is now considered the standard industry approach for Object to Relational Mapping (ORM) in the Java Industry.

The excerpt above is from Wikibooks:

Examples

The current version of the JPA specification is JPA 3.1, released on Apr 06, 2022.

Useful links

Related tags

FAQ

Spring Data JPA Update @Query not updating? While this question is about Spring Data JPA the underlying problem is about understanding the 1st level cache of JPA. See also the many duplicates pointing to that question.

One to many relationship doesn't work Spring boot jpa Again, asked in the context of Spring Data JPA it is really about JPA. It describes a common problem/misunderstanding with regard to bidirectional relationships.

51422 questions
14
votes
4 answers

How do I find a value in a column that just have unique values with EclipseLink?

You have the EntityManager.find(Class entityClass, Object primaryKey) method to find a specific row with a primary key. But how do I find a value in a column that just have unique values and is not a primary key?
Rox
  • 2,647
  • 15
  • 50
  • 85
14
votes
2 answers

NamedQuery: Best practices

When creating named queries in JPA, is there an accepted best practice for the names of these queries (eg. EntityName.allActive or findAllActiveFoos etc.) and also is it good to declare these named queries in the entity classes that they query or…
Clinton Bosch
  • 2,497
  • 4
  • 32
  • 46
14
votes
2 answers

JNDI lookup works fine using lookUp but not when used in persistence.xml of JPA

I am using tomcat connection pool, jpa, hibernate. The datasource i created in context.xml of tomcat works fine if I try to get it using : source = (DataSource) ((Context) c.lookup("java:comp/env")).lookup("jdbc/kids"); but if i specify this jndi…
Deepak Singhal
  • 10,568
  • 11
  • 59
  • 98
14
votes
3 answers

JPA: which implementations support lazy loading outside transactions?

EclipseLink can load lazy relationships in entities even after the entity manager that has created them is no longer available. With Hibernate this doesn't work, or at least didn't at the time of that post. What about other providers? OpenJPA and…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
14
votes
2 answers

How can I get all @Entity classes from a Persistence Unit?

Problem I'm writing a standalone utility program which, given a jar containing a JPA-2 annotated persistence unit, needs to programmatically get a list of all my @Entity classes in a particular persistence unit. I'd like to decide which of 2…
Tom Tresansky
  • 19,364
  • 17
  • 93
  • 129
14
votes
1 answer

Foreign key mapping inside Embeddable class

I am using eclipselink for JPA. I have an entity, which has a composite key fabricated out of two fields. Following is my Embeddable primary key class' fields(members). @Embeddable public class LeavePK { @ManyToOne(optional = false) …
Ahamed
  • 39,245
  • 13
  • 40
  • 68
13
votes
2 answers

Is @ManyToMany(mappedBy = ... ) + @OrderColumn supported by the JPA?

I have an entity mapped as following: @Entity @Table(name = "Groups") @IdClass(value = GroupId.class) public class Group implements Serializable { @Id @Column(name = "round_id") private Integer roundId; @Id @Column(name =…
Kawu
  • 13,647
  • 34
  • 123
  • 195
13
votes
4 answers

Loading JPA Entity from external Jar file

i have a project setup where i have modularized a project, and packaged a module into a jar file which gets included in the main project when we create a war and deploy it. The problem that i am facing is that, i have an Entity present in the…
Hrishikesh
  • 2,033
  • 1
  • 16
  • 26
13
votes
3 answers

When I use A JPA Query's getResultList(), are the results detached or managed?

When I have a JPA Query that I call .getResultList(), It gives me back a List of objects. Are the objects in that list managed or detached? That is, do I have to worry about merging or persisting them later if I make changes to them, or will those…
Philihp Busby
  • 4,389
  • 4
  • 23
  • 19
13
votes
3 answers

persistence.xml with Glassfish 3.1.1

I am very new to glassfish, JPA and so on and I have really problems with setting that up. What I am planning to do is a simple RESTful service with a persistent backend. I am using glassfish3 as application server and already deployed a simple REST…
Eddy
  • 1,451
  • 2
  • 10
  • 10
13
votes
3 answers

Hibernate 4 ClassCastException on LAZY loading while EAGER works fine

I have the following JOINED inheritance root entity for geographic areas (like continents, countries, states etc.): @Entity @Table(name = "GeoAreas") @Inheritance(strategy = InheritanceType.JOINED) public abstract class GeoArea implements…
Kawu
  • 13,647
  • 34
  • 123
  • 195
13
votes
6 answers

No [EntityType] was found for the key class [...] in the Metamodel

Entity: @Entity @Table(name="user_account") public class UserAccount implements Serializable{ private static final long serialVersionUID = -2606506548742732094L; @Id @GeneratedValue(strategy=GenerationType.TABLE) private Integer…
TGM
  • 1,659
  • 10
  • 30
  • 45
13
votes
1 answer

Table size using JPA query language

Using JPA query language, how do I determine the size (number of rows) in an entity (table)?
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
13
votes
4 answers

JPA @ManyToMany join table indexing

Hibernate allows adding indexes on @ManyToOne mappings by the use of @org.hibernate.annotations.Index. Is there a way to specify index for the join table in a @ManyToMany relation? If Entity A and Entity B have a @ManyToMany with A being the owning…
kmansoor
  • 4,265
  • 9
  • 52
  • 95
13
votes
3 answers

JPA or Hibernate for Java Persistence?

I'm researching the development of Enterprise Applications in Java, .NET and Groovy. For each platform, we're going to try how hard it is to realize a simple SOAP web service. We'll use the tools and libraries that are most commonly used, to…
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301