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
1074
votes
9 answers

What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?

What is the difference between CrudRepository and JpaRepository interfaces in Spring Data JPA? When I see the examples on the web, I see them there used kind of interchangeably. What is the difference between them? Why would you want to use one…
kseeker
  • 10,783
  • 3
  • 15
  • 7
1054
votes
16 answers

JPA EntityManager: Why use persist() over merge()?

EntityManager.merge() can insert new objects and update existing ones. Why would one want to use persist() (which can only create new objects)?
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
878
votes
33 answers

How to fix the Hibernate "object references an unsaved transient instance - save the transient instance before flushing" error

I receive following error when I save the object using Hibernate object references an unsaved transient instance - save the transient instance before flushing
Tushar Ahirrao
  • 12,669
  • 17
  • 64
  • 96
726
votes
18 answers

Difference between FetchType LAZY and EAGER in Java Persistence API?

What is the difference between FetchType.LAZY and FetchType.EAGER in Java Persistence API?
leon
  • 10,085
  • 19
  • 60
  • 77
679
votes
22 answers

What's the difference between JPA and Hibernate?

I understand that JPA 2 is a specification and Hibernate is a tool for ORM. Also, I understand that Hibernate has more features than JPA 2. But from a practical point of view, what really is the difference? I have experience using iBatis and now…
Anthony
  • 33,838
  • 42
  • 169
  • 278
628
votes
9 answers

JPA JoinColumn vs mappedBy

What is the difference between: @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY) @JoinColumn(name = "companyIdRef", referencedColumnName = "companyId") private List branches; …
Mike
  • 20,010
  • 25
  • 97
  • 140
601
votes
18 answers

Hibernate throws MultipleBagFetchException - cannot simultaneously fetch multiple bags

Hibernate throws this exception during SessionFactory creation: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags This is my test case: Parent.java @Entity public Parent { @Id …
blow
  • 12,811
  • 24
  • 75
  • 112
447
votes
4 answers

Create the perfect JPA entity

I've been working with JPA (implementation Hibernate) for some time now and each time I need to create entities I find myself struggling with issues as AccessType, immutable properties, equals/hashCode, ... . So I decided to try and find out the…
Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101
390
votes
20 answers

The JPA hashCode() / equals() dilemma

There have been some discussions here about JPA entities and which hashCode()/equals() implementation should be used for JPA entity classes. Most (if not all) of them depend on Hibernate, but I'd like to discuss them JPA-implementation-neutrally (I…
MRalwasser
  • 15,605
  • 15
  • 101
  • 147
379
votes
10 answers

What is the easiest way to ignore a JPA field during persistence?

I'm essentially looking for a "@Ignore" type annotation with which I can stop a particular field from being persisted. How can this be achieved?
m2o
  • 6,475
  • 6
  • 27
  • 24
375
votes
8 answers

Why does JPA have a @Transient annotation?

Java has the transientkeyword. Why does JPA have @Transient instead of simply using the already existing java keyword?
deamon
  • 89,107
  • 111
  • 320
  • 448
356
votes
37 answers

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

I am trying run a spring-boot application which uses hibernate via spring-jpa, but i am getting this error: Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set at…
Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
334
votes
6 answers

What's the difference between Hibernate and Spring Data JPA

What are the main differences between Hibernate and Spring Data JPA? When should we not use Hibernate or Spring Data JPA? Also, when may Spring JDBC template perform better than Hibernate and Spring Data JPA?
hard coder
  • 5,449
  • 6
  • 36
  • 61
333
votes
24 answers

PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate

I have a JPA-persisted object model that contains a many-to-one relationship: an Account has many Transactions. A Transaction has one Account. Here's a snippet of the code: @Entity public class Transaction { @Id @GeneratedValue(strategy =…
Paul Sanwald
  • 10,899
  • 6
  • 44
  • 59
321
votes
16 answers

How do I update an entity using spring-data-jpa?

Well the question pretty much says everything. Using JPARepository how do I update an entity? JPARepository has only a save method, which does not tell me if it's create or update actually. For example, I insert a simple Object to the database User,…
Eugene
  • 117,005
  • 15
  • 201
  • 306
1
2 3
99 100