Spring Data JPA IN Clause Example with WHERE Condition

Introduction In this example we will see how to work with IN clause with WHERE condition in SQL statement in Spring Data JPA. We will use MySQL server for this example. We will fetch selected rows or multiple rows selection as well as we will delete selected rows or multiple rows deletion from the table using IN operator with WHERE clause. We will use Spring transaction because we want to rollback our changes from database if any issue occurs during row deletion. The IN operator allows us to specify multiple…

Continue

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

In this tutorial we will see how to map custom query results into DTO in Spring Data JPA. Situations occur while you are unable to return the entity object(s) as results from your Spring Data JPA Repository and instead you are writing custom query or native query for your business requirements. So in such situations you need to convert result into DTO (data Trasfer Object). We will use @Query annotation to create custom queries in Spring Data JPA. It is also advisable to use DTO instead of entity class or…

Continue

Spring Boot MVC and Hibernate CRUD Example

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 tools. We will create the annotation based hibernate configuration with Spring Boot framework. We are going to use MySQL database as a persistence storage for our application.

Continue

Spring Boot MVC and JDBC 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 I am going to show you the same example but using Spring Boot framework. We are going to use both gradle and maven build tools to build the application. We are going to see how…

Continue

How to create Datasource in Spring Boot application

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 same for creating the Datasource. If you are using Spring JDBC API then you can use this Datasource object to create JdbcTemplate object. This Datasource object is also useful for working with Spring Data JPA…

Continue

Spring Data JPA Entity Graphs

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 several ways when working with mid to large size applications. In other cases, you just need to select a smallest set of information to optimize the performance of your application. Typically you do not have…

Continue

Spring Security – JDBC Authentication

In my previous tutorials, I have shown in-memory authentications Spring Security Form based Authentication – XML Configuration , Spring Security Form based Authentication – Annotations but in this tutorial I will show you how to authenticate user using Spring JDBC and Spring MVC web application to secure pages. I will create spring mvc based web application and I will configure Spring Security to protect a page from outside access. Spring Security allows to you to integrate security features with JEE web application easily, it takes care about all incoming HTTP requests…

Continue

Spring @PostConstruct and @PreDestroy Example

In this tutorial I will show you how we can use @PostConstruct and @PreDestroy annotation in Spring framework. @PostConstruct and @PreDestroy annotations are generally considered best practices for receiving life cycle callbacks in a modern Spring application. Using these annotations means that our beans are not coupled to Spring specific interfaces. Sometimes we need to load some data or perform initialization work after all necessary properties on the bean have been set by the container. In this example we will load data from database during application startup and set that…

Continue

Call Stored Procedure using Spring StoredProcedure

This tutorial will show you how we can call stored procedure using Spring StoredProcedure. I assume you have a basic idea on stored procedure what it does and what are the advantages of using stored procedure. I am going to build the project using both maven and gradle build tools. Related Posts: Call Stored Procedure using Spring SimpleJdbcCall Sometimes we need to call a stored procedure while a single SQL statement is unable to fulfil our requirements because, it permits to execute multiple SQL statements and it also allows us…

Continue

Call Stored Procedure using Spring SimpleJdbcCall

This tutorial will show you how we can call or execute stored procedure using Spring SimpleJdbcCall. SimpleJdbcCall API provides flexible methods to invoke stored procedure. We can use DataSource directly with SimpleJdbcCall or we can create JdbcTemplate using DataSource and use JdbcTemplate with SimpleJdbcCall API for calling the stored procedures. We can also use RowMapper or BeanProprtyMapper of type POJO class as a return type while executing stored procedures using Spring’s SimpleJdbcCall API. We are also going to use @Qualifier annotation for resolving ambiguity while using SimpleJdbcCall with DataSource and…

Continue