How-to articles, tricks, and solutions about JPA

Difference between FetchType LAZY and EAGER in Java Persistence API?

In the Java Persistence API (JPA), the FetchType enum is used to specify the strategy for fetching data from the database.

Hibernate throws MultipleBagFetchException - cannot simultaneously fetch multiple bags

If you are using Hibernate and you see the error "MultipleBagFetchException: cannot simultaneously fetch multiple bags", it means that you are trying to fetch multiple collections of an entity using a single Hibernate query.

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

To update an entity using Spring Data JPA, you will need to follow these steps:

JPA JoinColumn vs mappedBy

In a JPA entity mapping, the @JoinColumn annotation is used to specify the foreign key column for a many-to-one or one-to-one relationship.

No Persistence provider for EntityManager named

If you are seeing the error "No Persistence provider for EntityManager named [persistence-unit-name]" in your Java application, it means that the persistence provider (e.g.

Setting default values for columns in JPA

To set default values for columns in JPA (Java Persistence API), you can use the @Column annotation and the columnDefinition attribute.

Spring Boot - Cannot determine embedded database driver class for database type NONE

If you are seeing the error "Cannot determine embedded database driver class for database type NONE" in a Spring Boot application, it means that the application is trying to auto-configure an embedded database, but it is unable to determine which database

Spring Data JPA - "No Property Found for Type" Exception

This exception is usually thrown when you are trying to access a property that does not exist in the entity class you are querying.

Spring JPA selecting specific columns

To select specific columns using Spring JPA, you can use the @Query annotation and specify the columns in the SELECT clause of the JPQL query.

What is the meaning of the CascadeType.ALL for a @ManyToOne JPA association

In a JPA entity relationship, the CascadeType.ALL annotation specifies that all operations (persist, merge, remove, refresh, and detach) that are performed on the parent entity should be cascaded to the child entity.

What's the difference between JPA and Hibernate?

Java Persistence API (JPA) is a specification for object-relational mapping (ORM) in Java.