Inheritance vs. Composition in JPA

Introduction

«Don't repeat yourself» or «DRY». Developers try to adhere to this principle during software development. It helps to avoid redundant code writing and, as a result, simplifies its maintainability in the future. But how to achieve this principle in the JPA world?

There are two approaches: Inheritance and Composition. Both have their pros and cons. Let's figure out what they are on the not quite "real-world" but representative example.

Introduction to Spring Boot and JDBCTemplate: Refactoring to SpringData JPA

Refactoring is the process of modifying a software system without changing its desirable behavior. It was necessary to have an application integrated with the relational database using the Spring JDBC Template in the first parts. The Spring JDBC Template is a powerful tool that facilitates productivityHoweverthere is a way to simplify the code even further with Spring Data JPA. The purpose of this post is to refactor the project to use Spring Data JPA.

Spring Data JPApart of the larger Spring Data family, makes it easy to implement JPA-based repositories easilyThis module deals with enhanced support for JPA-based data access layers. It makes it easier to build Spring-powered applications that use data access technologies.

Spring Data JPA + QueryDSL: Taking the Best From Both Worlds

You can find the full project on GitHub using this link. There is a simple SpringBoot application with configured MySQL data source and initial database structure described as a Flyway migration.

Here we will concentrate only on the building persistence layer. As we deal with the relational database we will rely on the JPA specification. Let’s take a simple entity model like Author/Book as an example:

Spring Boot: Boost JPA Bulk Insert Performance by 100x

I was facing a problem where I wanted to insert millions of records into the database, which needed to be imported from the file.

So, I did some research around this, and I would like to share with you what I found which helped me improve the insert records throughput by nearly 100 times.

Finding and Fixing Spring Data JPA Performance Issues with FusionReactor

For several years, Spring Data JPA has established itself as one of the most commonly used persistence frameworks in the Java world. It gets most of its features from the very popular Hibernate object-relational mapping (ORM) implementation. The ORM features provide great developer productivity, and the basic functionality is very easy to learn. 

But as so often, you need to know a lot more than just the basic parts if you want to build enterprise applications. Without a good understanding of its internals and some advanced features, you will struggle with severe performance issues. Spring Data’s and Hibernate’s ease of use sometimes makes it way too easy to build a slow application.

Authentication with Spring Boot and Spring Security — JWT and Postgres

I am going to talk about what has become a very common requirement for web/cloud-applications these days: Authentication in the context of REST API calls using JSON Web Token, or commonly known as JAWT these days.

The idea behind JSON WebToken is to provide authentication in a stateless API world. The tokens are generated with a Key on the basis of Subject (could be a unique field or combination for a user e.g id, username etc.) using an encryption algorithm such as SHA-256 etc.

Client Oriented Dynamic Search Query Supporting Multiple Tables in Spring

Backdrop

To begin with, this an example primarily written in Springboot to leverage the benefits of Spring Data JPA. The main motive of this article to have a simple and common data search logic that applies to almost every table and is client-oriented. This article is heavily inspired by one from Eugen Paraschiv, I recommend going through his tutorials to learn Spring professionally.

Pre-Requisites for Getting Started

  • Java 8 is installed.
  • Any Java IDE (preferably STS or IntelliJ IDEA).
  • Basic understanding of Java and Spring-based web development along with Spring Data JPA.

I used Spring Initializer to add all the dependencies and create a blank working project with all my configurations. I used Maven as project build type and Java 8 as language, though this part is up to your choice as long as it is supported by spring. Below are my required dependencies which can easily be added from spring initializer. 

Introduction to Spring Data JPA, Part 3: Unidirectional One to Many Relations

We will look into unidirectional one-to-many relations. We will use Cascade Types, a constructor-based dependency injection by removing the @Autowired annotation. We will accomplish this with a small implementation where we will handle the DELETE operation, understand  @PathVariable annotation, use Orphan removal, and the @Transaction  annotation.

Let us consider an organization. Here there will be many employees, each taking up different tasks. Let us call the employees users and classify their tasks into roles they play. Some may be performing managerial task, so we'll give them the role MANAGER. Some may be performing system administration tasks, so we'll give them the role ADMIN.  

Introduction to Spring Data and Spring Data JPA

In this article, we take a look at Spring Data and Spring Data JPA.

You Will Learn

  • The challenges with existing data store integration solutions.
  • What Spring Data is.
  • The aims of Spring Data.
  • How Spring Data abstracts talking to different data stores.
  • What Spring Data JPA is.
  • How Spring Data JPA helps in making JPA easier.

Challenges With Existing Data Store Solutions

Let's start with looking at problems with some of the existing solutions for storing data to data stores.

How to Use Spring Data JPA and Spring Boot With MariaDB

As you may already be aware, Spring Data JPA is part of the larger Spring Data family. In this article, we are going to use Spring Data JPA along with Spring Boot to communicate with the MariaDB database.

Dependencies

With Spring Boot:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


Spring Boot With Spring Data JPA

Welcome to the Spring Boot with Spring Data JPA tutorial! In this tutorial, we are going to see how Spring Data JPA provides complete abstraction over the DAO layer. We don’t need to write the implementation for the DAO layer anymore; Spring Data auto-generates the implementation DAO implementations.

We already had an introduction to Spring Boot, and for this tutorial, we will use Spring Boot along with Spring Data. You will also see how Spring Boot auto-configuration helps to get data source configurations done, hassle-free.