Category: Spring

  • How to use Lombok with Spring Boot

    Project Lombok is one of those libraries that a lot of developers appreciate. Not only because it saves you a lot of time writing boilerplate code, but you also end up with leaner and cleaner code which is easier and more pleasant to read. If you are considering to introduce Lombok to your project, then…

  • 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…

  • Auditing using Spring boot, MongoDB and JaVers

    In this tutorial, we will discuss how to audit data and generating audit logs and data history entries using JaVers in a Spring boot and MongoDB environment. Prerequisites If you currently do not have a Spring boot environment set up with a MongoDB backend, then we suggest that you check out our Spring boot and MongoDB…

  • Spring boot and MongoDB configuration example

    In this post, we will configure a Spring boot application to use a MongoDB persistence back-end. BTW, if you are developing on a Windows machine, then you can also check out our guide for how to install and get started with MongoDB on Windows. Introduction MongoDB is a NoSQL, cross-platform, document based database engine. It…

  • Prototype vs Singleton Spring Beans – How-to, Differences and Uses

    In this post, we will discuss two different types of Spring beans, namely singleton and prototype beans. We will also discuss when is it preferred to use prototype beans and when to use singleton beans. Singleton beans Most beans that you will use or encounter are singleton beans. Singleton beans are initialized only once. Either…

  • How to obtain application property values in a Spring Boot application

    In this guide, we will discuss two ways to obtain application property configuration values inside a Spring boot application. We will focus on properties that are loaded via an application.properties or an application.yml file. But all loaded properties in your application context should also be obtainable via the discussed methods. We will discuss the @Value…

  • How to configure Spring beans using constructor injection

    In this post, we will focus on configuring Spring beans in a Spring-boot environment using Java configuration and constructor injection. This example should be valid for Spring version 4.3 and later. Let us start by discussing a couple of basic concepts. What is constructor injection? Constructor injection is the process of injecting Spring dependencies into…

  • 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…

  • 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…