Category: JPA
-
How to use database sequences with JPA/Hibernate entities
When creating a new database table, you can decide how the table’s identifier column value will be generated. One way of doing this is to use a database sequence. A database sequence can be used to generated the next value or next value range that will be reserved for usage as table row identifier values.…
-
How to configure sharding with Lucene, Hibernate search & Spring Boot
In this guide, we will explore how to implement sharding with Lucene and Hibernate Search in a Spring boot and JPA environment. We will discuss why is it useful and when is it a good idea to implement it. I would also suggest that you read our guide here if you are just getting started with…
-
Configuring @PostLoad and @PostUpdate in JPA/Hibernate
In this post we will discuss how to use the @PostLoad and @PostUpdate annotations in Hibernate/JPA. This tutorial assumes that you have some knowledge of the @PreUpdate and @PrePersist annotations. If you are not familiar with these annotations, then please check our earlier post here. What are the @PostLoad and @PostUpdate annotations The @PostLoad and…
-
How to use @PrePersist and @PreUpdate in JPA/Hibernate
In this post, we will discuss the @PrePersist and the @PreUpdate annotations and how and why they are used in a JPA / Hibernate environment to configure entity insertion and update hooks. When configuring hooks and listeners for database operations, we need to be careful not to negatively affect the performance of the database or…
-
Troubleshooting a PropertyNotFoundException in JPA
In this post, we discuss yet another reason for having a mapping error from Hibernate. This specific one is called a PropertyNotFoundException. If you have made sure that your property is correctly mapped to the database table, with correct column names and a getter and a setter for the property, then read on!. Let us…
-
JPA / Hibernate – Mapping One-to-One relationships
In this tutorial, we will discuss how to map and configure One-to-One relationships in JPA and Hibernate. What are One-To-One relationships? One to One relationships in databases define the relationship between two different entities, where the first entity can be related to zero or one of the second entity. For example, a user can have…
-
How to manage JPA bidirectional relationships properly
In this troubleshooting guide, we will explore how to properly map bidirectional relationships and common mapping pitfalls that cause exceptions such as DataIntegrityViolationException, a ConstrainViolationException and a PropertyValueException. We will take an unusual approach in this guide by first building the faulty software, and then we will discuss how and why this should be fixed.…
-
Configuring and mapping database tables to JPA entities
In this post, we will explore how to map a database tables to JPA Entities. In our example, we will use a Spring Boot environment, JPA 2.2 and Hibernate 5.3.7 . However, the information presented here should apply to any environment with a JPA version of 2.1 or later. Introduction In our previous post, we discovered…
-
org.hibernate.MappingException: Could not determine type for: java.util.List – Causes & Fixes
In this post, we will explore a very common Hibernate error, namely a MappingException caused by missing annotations on the Entity getters and fields. The error Let us check the following stack trace as an example: java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource…
-
Getting started with Spring boot 2 and JPA
In this tutorial, we will build a simple Spring boot 2 application with access to a Postgres database using JPA. Background: Before we get started, let us get a couple of definitions out of the way. What is JPA? JPA stands for the “Java Persistence API”. It is a java specification that defines how data…