Skip to main content
The 2024 Developer Survey results are live! See the results

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.

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)?
Aaron Digulla's user avatar
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
Tushar Ahirrao's user avatar
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?
leon's user avatar
  • 10.3k
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 ...
Anthony's user avatar
  • 35.4k
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 ...
Mike's user avatar
  • 20.7k
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 @...
blow's user avatar
  • 13.1k
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/...
Stijn Geukens's user avatar
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 ...
MRalwasser's user avatar
  • 15.9k
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?
m2o's user avatar
  • 6,644
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?
deamon's user avatar
  • 91.3k
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 ...
Kleber Mota's user avatar
  • 8,815
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 ...
Paul Sanwald's user avatar
  • 11.2k
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 ...
hard coder's user avatar
  • 5,625
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 ...
Eugene's user avatar
  • 120k

15 30 50 per page
1
2 3 4 5
3481