DataIntegrityViolationException & ConstraintViolationException- Managing JPA bidirectional relationships properly

Troubleshooting DataIntegrityViolationException,  PropertyValueException & ConstraintViolationException – Managing JPA bidirectional relationships properly   In this troubleshooting guide, we will explore one of the most common causes of a DataIntegrityViolationException, a ConstrainViolationException and a PropertyValueException. We will set up our database tables and our entity models in order to reproduce the exception, and then we will discuss how the …


DataIntegrityViolationException & ConstraintViolationException- Managing JPA bidirectional relationships properly

Troubleshooting DataIntegrityViolationException,  PropertyValueException & ConstraintViolationException – Managing JPA bidirectional relationships properly   In this troubleshooting guide, we will explore one of the most common causes of a DataIntegrityViolationException, a ConstrainViolationException and a PropertyValueException. We will set up our database tables and our entity models in order to reproduce the exception, and then we will discuss how the …


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 …


Mixing property And field javax.persistence annotations causes org.hibernate.MappingException

The error: In this post, we will explore a very common Hibernate error, namely a MappingException caused by missing annotations on the Entity getters and fields. Let us check the following stack trace as an example:  

  The implementation:   Now let us take a look at the code. The implementation contains two …


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 …


Create, configure and test an MBean in Spring boot using Java config and Jolokia

Summary: In this article, we will create a new custom MBean. We will show how to configure this bean and then we will test it using Jolokia (JMX over HTTP).   Prerequisites: If you have not yet configured Jolokia, then we suggest that you go over this article https://nullbeans.com/how-to-configure-jolokia-on-a-spring-boot-server/ before you proceed.   Introduction: Managed beans (MBeans) …


How to configure Jolokia on a Spring boot server

Summary:   In this article, we will find out how to configure Jolokia on a Spring Boot 2 server. We will also configure Jolokia on a different management port and a different base URL.   Background:   Jolokia is a JMX over HTTP bridge that allows system administrators to access their MBeans and JMX functionalities …


The Java Comparable interface – Automatically sort collections

Summary: In this post, we will explore how to use the Java comparable interface to automatically sort collections of any classes. We will use the Java Collections from the util library as an example.   Introduction: Java interfaces are one of the most powerful features of the object oriented programming language. When a class implements …


How to squeeze more performance out of ArrayLists

In this post we will discuss how to improve the performance of Java programs that utilize ArrayLists by setting the list’s initial capacity.   ArrayLists and lists in general are great data structures for storing data. They are convenient for when we don’t know how large our data set. However, this comes with a performance …


Spring Boot Freemarker Configuration Example

Introduction: Freemarker is a powerful Java template engine. It can be used to generate basically anything, from HTML pages, configuration files, e-mails, or anything else. All you need to do is define your template, use Java to prepare the data, and use the Freemarker engine to process your data with the given template to produce …


Java NullPointerException – examples, causes and fixes

Probably one of the most common and annoying exceptions to be encountered by any Java developer is the dreaded “NullPointerException”. A null pointer exception is thrown when an “illegal” referencing of a null object is performed. A “null” object is an object which is not initialized. Let us explore some examples of how a null …