N+1 Selects problem in Hibernate and How to Avoid it

Let us talk about the infamous N+1 selects problem in hibernate entities and how to solve it with some examples. You may have also heard it as an N+1 queries problem in some places. What is the N+1 selects problem? The N+1 selects problem is a performance anti-pattern where an application makes N+1 small queries to the…

Accessing Command-line Arguments in Spring Boot

Let’s learn how to read command-line arguments of a Spring Boot Application. Like any other java program, Spring Boot can take program parameters of application parameters on startup. But spring boot goes extra-mile to argument parsing. Lets get into the details. CommandLineRunner and ApplicationRunner These two interfaces are similar in nature and help you access…

Paginating RESTful API responses in Spring MVC

Pagination lets you split large RESTful API responses from Spring MVC into smaller chunks called pages. In this post, let us see how to use Spring MVC and Spring JPA to paginate a JSON response from a spring boot application. Pagination and Sorting in Spring MVC As we have seen earlier, we can implement pagination…

Pagination and Sorting in Spring JPA

Let’s learn how to use Process a large number of records effectively using Pagination and Sorting in Spring Data JPA. What is Pagination and Sorting? Most often, the result set from a database can be overwhelming. It can be overwhelming to a point where systems crash because they can’t handle that much data on a…

Spring Data JPA: @OneToMany Annotation

In this post, We will take a look at one to many mapping with spring data jpa. With a simple spring boot application, we will walkthrough through how to implement @OneToMany annotation the right way. One To Many Relationship mapping In the object-relational model, the One-To-Many relationship refers to One parent entity that has a…

Spring Data JPA @ManyToOne Annotation

Let us learn how to use @ManyToOne annotation in Spring Data JPA with a spring boot application as an example. What is Many To One Relationship? The many-to-one mapping or association means that one parent record can have multiple child records. In other words, multiple records of a table can associate themselves with a common…

Introduction to Spring Data JPA

The Spring JPA ( also known as spring Data JPA) is one of the spring modules that deal with storing, retrieving, and searching entity objects. In this post, we will take a look at spring JPA in detail using the spring boot application. Introduction Spring Data JPA revolves around the org.springframework.data.repository.Repository interface. This interface acts…

Connection to a database from Spring Boot

Spring Boot lets you make connections to a database of any type with little to no configuration. In this post, we will see how to connect to a MySQL database with spring boot. Step 1: Add a database starter In spring boot, a starter is a special type of dependency that comes with some auto-configuration….

Replacing Tomcat with Undertow in Spring Boot

In this post, we will learn how to replace Tomcat with Undertow in Spring Boot with an example. What is Undertow? Undertow is the new embeddable web server written in Java. It has great HTTP2 support, it provides blocking and not blocking APIs based in Java NiO. And most importantly, the undertow is lightweight. Replace…

Jetty with Spring Boot – Replacing tomcat with Jetty

Let’s learn how to change the default tomcat server with a jetty server in Spring boot with detailed instructions. Tomcat and Jetty are the most known web servers in Java. They both have identical features and have the same set of features to offer. Even though I personally prefer tomcat, there are ways to update…