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.
52,201
questions
1068
votes
16
answers
775k
views
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)?
905
votes
35
answers
1.1m
views
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
748
votes
18
answers
783k
views
Difference between FetchType LAZY and EAGER in Java Persistence API?
What is the difference between FetchType.LAZY and FetchType.EAGER in Java Persistence API?
678
votes
22
answers
597k
views
What's the difference between JPA and Hibernate? [closed]
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 ...
637
votes
9
answers
624k
views
JPA JoinColumn vs mappedBy
What is the difference between:
@Entity
public class Company {
@OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY)
@JoinColumn(name = "companyIdRef", referencedColumnName ...
620
votes
18
answers
494k
views
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
@...
448
votes
4
answers
187k
views
Create the perfect JPA entity [closed]
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/...
397
votes
20
answers
144k
views
The JPA hashCode() / equals() dilemma [closed]
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 ...
392
votes
10
answers
330k
views
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?
385
votes
8
answers
458k
views
Why does JPA have a @Transient annotation?
Java has the transient keyword. Why does JPA have @Transient instead of simply using the already existing java keyword?
374
votes
40
answers
765k
views
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 ...
349
votes
24
answers
721k
views
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 ...
348
votes
6
answers
187k
views
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 ...
335
votes
17
answers
904k
views
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 ...