Introduction In this example I will show you how to convert entity class to DTO (Data Transfer Object) class and DTO class to entity class using MapStruct. So, MapStruct will map entity class to DTO class or vice versa. This example will test both from RESTful webservices and standalone main class. Spring Boot provides CommandLineRunner…

Posted in Spring Boot Spring JPA

Spring Boot Data JPA Entity DTO Mapping Using MapStruct

Table of Contents Introduction Why do you want to connect to multiple database Prerequisites Project Setup Application Properties DataSource Configurations DAO Class Source Code Introduction Here I am going to show you how to connect to Oracle data source using JDBC LDAP URL. I am going to create multiple data sources for connecting to multiple…

Posted in Database Spring Boot Spring JDBC

Connecting To Multiple Oracle Data Sources Using JDBC LDAP URLs

Introduction In this example I am going to show you Spring Security Pre-authentication hasrole with Spring Data JPA. In my another example I had shown the similar example on Spring Security Pre-Authentication with Spring JDBC Template. There are situations where you want to use Spring Security for authorization, but the user has already been reliably…

Posted in Spring Boot Spring REST Spring Security

Spring Security Pre-Authentication with Spring Data JPA

Introduction Here I am going to build a system to log online user activity in Spring Boot applications using HandlerInterceptor interface. As an application owner you may want to track your user activities, such as, which page they are accessing, from where requests were made to your application, from which pages to which pages they…

Posted in Spring Boot Spring JPA Spring REST

How To Log Online User Activity In Spring Boot Applications

Introduction Spring Data JPA provides multiple ways of selecting or fetching data from database server and one of the ways is using @NamedQuery or @NamedQueries. @NamedQuery and @NamedQueries can be created using XML configuration, external properties file or using Java based annotation config. Spring Data JPA supports both JPQL and SQL native named queries. Here…

Posted in Spring Boot Spring JPA

Spring Data JPA @NamedQuery and @NamedQueries Example

Introduction In this example you will see how to work with IN clause with WHERE condition in SQL statement in Spring Data JPA. I will use MySQL server for this example. I will fetch selected rows or multiple rows selection as well as I will delete selected rows or multiple rows deletion from the table…

Posted in MySQL Spring JPA Spring REST

Spring Data JPA IN Clause Example With WHERE Condition

Introduction In this tutorial I will show you how to map custom query results into DTO in Spring Data JPA. Situations may occur while you are unable to return the entity object(s) as results from your Spring Data JPA Repository and instead you need to write custom query or native query for your business requirements….

Posted in Spring Boot Spring JPA

How to map Custom Query Results into DTO in Spring Data JPA

Introduction In this tutorial we will create an example on Spring Boot MVC and Hibernate CRUD. CRUD is an acronym that means Create, Read, Update and Delete operations. In my other tutorial I had also created Spring Boot MVC and JDBC CRUD Example. We will build the tutorial example using both maven and gradle build…

Posted in Hibernate MySQL Spring Boot

Spring Boot MVC and Hibernate CRUD Example

Introduction In my other tutorial I had shown how to create an example on Spring MVC and JDBC CRUD example using annotations only, but here I am going to use Spring Boot framework. I did not update the other tutorial keeping in mind if someone still needs the example using Spring framework only. Here also…

Posted in Spring Boot Spring JDBC Spring MVC Spring Transaction

Spring Boot MVC and JDBC CRUD Example

In this tutorial we will see how to create Datasource in Spring Boot application in different ways. We need to create datasource in our applicationin order to interact with database and perform database operations in Spring or Spring Boot applications. You can use database vendor as per your project’s requirement but the underlying concept is…

Posted in Spring Spring Boot

How to create Datasource in Spring Boot application

Introduction In this post I will show you how to configure JNDI datasource with Spring Boot applications. JNDI (Java Naming Directory Interface) data source is very similar to JDBC (Java Database Connectivity) data source. I will show examples on Oracle as well as MySQL database servers. The MySQL version example is downloadable at the end…

Posted in Spring Boot Spring JPA

Configure JNDI DataSource with Spring Boot

One of the important features in Spring Data JPA or simply JPA is the ability to specify fetch plans using Entity Graphs. This is useful since it allows you to customize the data, which is retrieved with a query or find operation. It is expected to display data from the same entity in different and…

Posted in MySQL Spring Boot Spring JPA

Spring Data JPA Entity Graphs