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
15
votes
4 answers

JPA Database structure for internationalisation

I am trying to get a JPA implementation of a simple approach to internationalisation. I want to have a table of translated strings that I can reference in multiple fields in multiple tables. So all text occurrences in all tables will be replaced by…
IrishDubGuy
  • 1,053
  • 2
  • 9
  • 18
15
votes
2 answers

MultipleBagFetchException thrown by Hibernate

I want to have an option in my repository layer to eager load entites, so I tried adding a method that should eager load a question entity with all the relationships, but it throws MultipleBagFetchException. How can I fix this? I am using Hibernate…
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
15
votes
5 answers

Call method in JPA

I'm using ObjectDB with JPA. I would like to call myMethod(). For example: entityManager.createQuery("SELECT ... FROM ... WHERE MyClass.myMethod() = 100") Is it possible? Maybe any annotation is required before method in the class? @Entity public…
Martynas
  • 2,545
  • 7
  • 30
  • 36
15
votes
1 answer

Create Query matching for current date

Possible Duplicate: Example of using CURRENT_DATE in JPA query I am trying to add a query to my repository to compare a date stored in the db against the current date. My query is like this: @Query("Select c from Customer c where c.terminated !=…
pushy
  • 9,535
  • 5
  • 26
  • 45
15
votes
4 answers

LazyInitializationException in JPA and Hibernate

I know that this question has been ask numerous times here and across the internet and I have read through many of those answers but I still don't understand the proper way to solve this problem. I am experimenting with Spring MVC and JPA and every…
Eddie
  • 919
  • 2
  • 9
  • 21
15
votes
5 answers

TransactionRequiredException: Executing an update/delete query

I'm having a tough time finding a solution to my problem. I have a service class, which contains a method to set a verification flag upon login. @Service("userRolesService") @Repository @Transactional public class UserRolesService { public void…
pushy
  • 9,535
  • 5
  • 26
  • 45
15
votes
5 answers

Deep Copy in JPA

I would like to make a deep copy of an entity in JPA. I found an interesting discussion here: http://forums.java.net/jive/thread.jspa?messageID=253092&tstart=0 It sounded like the proposed solution was to set all @Id's to zero. Here's my basic…
User1
  • 39,458
  • 69
  • 187
  • 265
15
votes
1 answer

Composite primary key, foreign key. Reference to object or key?

I have two classes Foo and Bar. The tables in the database look like this: |Foo| |id : INT (PK) | bar_id : INT (PK, FK) | |Bar| |id : INT (PK) | Normally I would map it like this: @Entity public class Bar { @Id @Column(name = "id") …
siebz0r
  • 18,867
  • 14
  • 64
  • 107
15
votes
1 answer

JPA Hibernate Metamodel generation through maven

I followed the JPA modelgen guide and i was able to generate the canonical metamodel which i need. With this pom set up: maven-compiler-plugin
geneqew
  • 2,401
  • 5
  • 33
  • 48
15
votes
2 answers

What are the difference between: sequence id using JPA @TableGenerator, @GeneratedValue vs database Auto_Increment

Q1.: What is the difference between applying sequence Id in a database using A. CREATE TABLE Person ( id long NOT NULL AUTO_INCREMENT ... PRIMARY KEY (id) ) versus B. @Entity public class Person { @Id …
Thang Pham
  • 38,125
  • 75
  • 201
  • 285
14
votes
1 answer

Join two un-related tables using JPA EntityManager

I need to join two JPA entities on a property when there is no FK/PK relation between the two. I am using Hibernate and can use HQL query like this select foo, bar from FooEntity as foo, BarEntity as bar where foo.someothercol = 'foo' and…
ajay
  • 651
  • 2
  • 8
  • 16
14
votes
7 answers

How to use joda time with JPA (eclipselink)?

I tried to use the DataTime in my entity class. Adding @Temporal(TemporalType.DATE) above the field, I got the error saying "The persistent field or property for a Temporal type must be of type java.util.Date, java.util.Calendar or…
Ahamed
  • 39,245
  • 13
  • 40
  • 68
14
votes
3 answers

Hibernate: Used mappedBy on class that extends another class annotated as JoinedSubclass?

The following doesn't work: @Entity class Owner { @OneToMany(mappedBy="owner", cascade = {CascadeType.ALL}) protected Set getBSet() { .. } } @Entity @Inheritance(strategy=InheritanceType.JOINED) class A { @ManyToOne public…
GreenieMeanie
  • 3,560
  • 4
  • 34
  • 39
14
votes
2 answers

JPQL Query Annotation with Limit and Offset

I have a repository interface with some abstract methods where I use the @Query annotation. Now I would like to add limit and offset support to this queries. example: public interface ProductRepository extends CrudRepository { …
mjspier
  • 6,386
  • 5
  • 33
  • 43
14
votes
3 answers

How to combine LEFT JOIN and Where clause with JPQL?

I have two JPA entities : Schedule (containing a list of reservations) Reservation (containing a Date field : Date resDate) My goal is to only retrieve reservations matching a date parameter (planningDate) while retrieving all schedules no matter…
Mik378
  • 21,881
  • 15
  • 82
  • 180