
- Spring Boot ORM - Home
- Spring Boot ORM - Overview
- Environment Setup
- Spring Boot ORM - JPA
- Spring Boot ORM & Spring Data JPA
- Spring Boot ORM - Create Project
- Application.properties
- Spring Boot ORM - Update Project
- Spring Boot ORM - Test Hibernate
- Spring Boot ORM & EclipseLink
- Maven EclipseLink
- Update Project EclipseLink
- Spring Boot ORM - Test EclipseLink
Spring Boot ORM - Quick Guide
Spring Boot ORM - Overview
The Spring Framework integrates well with ORM frameworks like Hibernate, Java Persistence API (JPA), Java Data Objects (JDO) and iBATIS SQL Maps. Spring provides resource management, data access object (DAO) implementations, and transaction strategies. Spring allows to configure ORM library features through dependency management. Spring maintains a uniform DAO Exception hiearchies and a generic transaction management for all the ORM libraries it supports.
Spring IoC container facilitates ORM configurations and easy deployment. Following are the key benefits of using Spring framework to create ORM DAO.
Easy to Test − Using spring IoC, an ORM implementation can be easily configured. Each piece of persistence unit can be tested in isolation.
Common Data Access Exception − Spring wraps ORM Tools exceptions to a common runtime exception as DataAccessException. This approach helps to handle most persistence exception (non-recoverable) in appropriate layers. No need to handle ORM specific boilerplate catch/throws/exception declarations.
General Resource Management − Spring application contexts manages persistence objects, their configurations easily. For example, Hibernate SessionFactory instances, JPA EntityManagerFactory instances, JDBC DataSource instances, iBatis SQL Maps configuration objects and other related objects. Spring handles the local as well JTA transaction management by itself.
Integrated transaction management − Spring AOP can be used to wrap an ORM code with a declarative AOP styled interceptor either using @Transaction annotation or by specifying transaction AOP advice in XML configuration file. Spring handles transaction semantics, exception handling, rollback and so on. Spring allows to swap transaction managers without affecting the ORM code.
Spring Boot ORM - Environment Setup
This chapter will guide you on how to prepare a development environment to start your work with Spring Framework. It will also teach you how to set up JDK, Tomcat and Eclipse on your machine before you set up Spring Framework −
Step 1 - Setup Java Development Kit (JDK)
Java SE is available for download for free. To download click here, please download a version compatible with your operating system.
Follow the instructions to download Java, and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set environment variables to point to correct installation directories.
Setting Up the Path for Windows 2000/XP
Assuming you have installed Java in c:\Program Files\java\jdk directory −
Right-click on 'My Computer' and select 'Properties'.
Click on the 'Environment variables' button under the 'Advanced' tab.
Now, edit the 'Path' variable and add the path to the Java executable directory at the end of it. For example, if the path is currently set to C:\Windows\System32, then edit it the following way
C:\Windows\System32;c:\Program Files\java\jdk\bin
Setting Up the Path for Windows 95/98/ME
Assuming you have installed Java in c:\Program Files\java\jdk directory −
Edit the 'C:\autoexec.bat' file and add the following line at the end −
SET PATH=%PATH%;C:\Program Files\java\jdk\bin
Setting Up the Path for Linux, UNIX, Solaris, FreeBSD
Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.
For example, if you use bash as your shell, then you would add the following line at the end of your .bashrc −
export PATH=/path/to/java:$PATH'
Alternatively, if you use an Integrated Development Environment (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, you will have to compile and run a simple program to confirm that the IDE knows where you have installed Java. Otherwise, you will have to carry out a proper setup as given in the document of the IDE.
Step 2 - Setup Spring Tool Suite
All the examples in this tutorial have been written using Spring Tool Suite IDE. So we would suggest you should have the latest version of Spring Tool Suite installed on your machine.
To install Spring Tool Suite IDE, download the latest Spring Tool Suite binaries from www.eclipse.org/downloads. Once you download the installation, unpack the binary distribution into a convenient location. For example, in C:\sts\sts-4.23.1.RELEASE on Windows, or /usr/local/sts/sts-4.23.1.RELEASE on Linux/Unix and finally set PATH variable appropriately.
Spring Tool Suite can be started by executing the following commands on Windows machine, or you can simply double-click on SpringToolSuite4.exe
E:\sts\sts-4.23.1.RELEASE\SpringToolSuite4.exe
Eclipse can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine −
$/usr/local/sts/sts-4.23.1.RELEASE/SpringToolSuite4
Step 3 - Setup Spring Boot Project
Now if everything is fine, then you can proceed to set up your Spring Boot. Following are the simple steps to download and install the Spring Boot Project on your machine.
Go to spring Initializr link to create a spring boot project, https://start.spring.io/.
Select project as Maven Project.
Select language as Java.
Select Spring Boot version as 3.3.3.
Set Project Metadata - Group as com.tutorialspoint, Artifact as springbootorm, name as springboot-h2, Description as Demo project for Spring Boot ORM and package name as com.tutorialspoint.springbootorm.
Select packaging as Jar.
Select java as 21.
Add dependencies as Spring Web, Spring Data JPA, H2 Database and Spring Boot DevTools.
Now click on GENERATE Button to generate the project structure.

Once the maven based spring boot project is downloaded, then import the maven project into eclipse and rest eclipse will handle. It will download the maven dependencies and build the project to make it ready for further development.
Step 4 - POSTMAN for REST APIs Testing
POSTMAN is a useful tool to test REST Based APIs. To install POSTMAN, download the latest POSTMAN binaries from www.postman.com/downloads/. Once you download the installable, follow the instructions to install and use it.
Spring Boot ORM - JPA
Java Persistence API (JPA) is a collection of classes and interfaces that allow object/relational mapping of Java objects with databases. In JPA, Entity classes are defined in persistence.xml file. Spring Boot does not use persistence.xml. Instead it uses "Entity Scanning" is the process of finding and registering Entity classes with the persistence provider.
What is Entity Scanning?
Entity Discovery − When the provider finds a class with the @Entity annotation, it recognizes it as a persistent entity and registers it.
Persistence Unit − The discovered entities are then associated with a persistence unit, which defines a set of entities managed by a single EntityManager.
Scanning Packages − The JPA provider scans specified packages or directories for classes annotated with the @Entity annotation.
By default the auto-configured packages are scanned.
Configuring Entity Scanning in Spring Boot
-
Default Scanning − By default, Spring Boot scans the package of your main application class and its sub-packages for entity classes.
-
Customizing Scanning − You can use the @EntityScan annotation to specify the packages to scan. For example:
@SpringBootApplication @EntityScan(basePackages = {"com.example.entities"}) public class Application { // ... }
Spring Data JPA Repositories
Spring Data JPA implements interfaces that are used to access data from database (relational, NoSQL or anything else). Spring Data repositories extend from either Repository or CrudRepository.
@Repository public interface EmployeeRepository extends CrudRepository<Employee, Integer> { }
Creating and Deleting Databases
JPA databases are automatically created if you use an embedded database like H2, Derby. To create and drop tables, your application.properties should look like this −
spring.jpa.hibernate.ddl-auto=create-drop
Mapping associations between classes
Mapping associations can be of two types −
Unidirectional association − In this association, only one entity holds a reference to the other. For example, One to Many or Many to One relationship.
Bidirectional association − In a bidirectional association, both entities (source and target) have a relationship field that refers to each other. For example, Many to Many relationship.
One-to-Many Relationship (Unidirectional)
Imagine a Department entity and its Employees. Each department has many employees, but each employee belongs to one department only.
Department.java
package com.tutorialspoint; import javax.persistence.*; import java.util.*; @Entity public class Department { @Id private Long id; @OneToMany @JoinColumn(name = "department_id") private List<Employee> employees; public Department() {} public Long getId() { return id; } public void setId(Long id) { this.id = id; } public List<Employee> getEmployees() { return employees; } public void setEmployees(List<Employee> employees) { this.employees = employees; } }
Employee.java
package com.tutorialspoint; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class Employee { @Id private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; } }
Many-to-One Relationship (Unidirectional)
Consider a Student and a School. Each student can be enrolled in only one school, but each school can have multiple students.
Student.java
package com.tutorialspoint; import javax.persistence.*; @Entity public class Student { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; @ManyToOne @JoinColumn(name = "school_id") private School school; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public School getSchool() { return school; } public void setSchool(School school) { this.school = school; } }
School.java
package com.tutorialspoint; import javax.persistence.Entity; import javax.persistence.Id; import java.util.List; @Entity public class School { @Id private Long id; private List<Student> students; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public List<Student> getStudents() { return students; } public void setStudents(List<Student> students) { this.students = students; } }
Many-to-Many Relationship (Bidirectional)
In a bidirectional association, both entities (source and target) have a relationship field that refers to each other. Imagine a Book and an Author. Each book has one author, but each author can write multiple books.
Book.java
package com.tutorialspoint; import javax.persistence.*; @Entity public class Book { @Id private Long id; private String title; @ManyToOne @JoinColumn(name = "author_id") private Author author; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Author getAuthor() { return author; } public void setAuthor(Author author) { this.author = author; } }
Author.java
package com.tutorialspoint; import javax.persistence.*; import java.util.List; @Entity public class Author { @Id private Long id; private String name; @OneToMany(mappedBy = "author") private List<Book> books; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<Book> getBooks() { return books; } public void setBooks(List<Book> books) { this.books = books; } }
Spring Boot ORM - Create Project
Using STS (Spring Tool Suite), select File −> Import −> Existing Maven Project and click Next.

Select the project downloaded and extracted from spring initializr during environment setup, as shown below:

Click on Finish button and a new project will be created.

Now as we've our project ready, let check following dependencies in pom.xml.
Spring Boot Starter Framework libraries
MySQL Connector
Other related dependencies.
As we are using spring boot, its starter projects automatically handles most of the dependencies.
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.tutorialspoint</groupId> <artifactId>springbootorm</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springbootorm</name> <description>Demo project for Spring Boot ORM</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>21</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
Spring Boot ORM - application.properties
Spring boot reads application as well as persistence related properties from application.properties. Here we can configure the hibernate or any other ORM framework specific properties as well. We're using generic properties so that we can switch between ORM without changing much code. By default, spring boot configure hibernate as ORM provider if no other ORM library is specified in POM.xml.
Create application.properties under src −> main −> resources directory and update as shown below.
application.properties
spring.application.name=springbootorm #datasource configurations spring.datasource.url=jdbc:mysql://localhost:3306/tutorialspoint spring.datasource.username=root spring.datasource.password=root@123 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # show SQL spring.jpa.show-sql: true # DDL generation spring.jpa.generate-ddl=true
Following is the description of key attributes of application.properties.
spring.datasource − Database specific attributes like connection url, username, password, driver class etc.
spring.jpa − jpa specific attributes like to show sql, to allow create tables etc.
Spring Boot ORM - Update Project
Let's now add a REST API to our the spring application which can add, edit, delete and display employee(s).
Entity
Create an entity Employee to persist Employee Object to Employee Table.
Employee.java
package com.tutorialspoint.springbootorm.entity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; // entity class to persist object to Employee Table @Entity public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; private int age; private String email; // setter, getter methods public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
Repository
Create a Repository to perform database operations on Employee Object.
EmployeeRepository.java
package com.tutorialspoint.springbootorm.repository; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import com.tutorialspoint.springbootorm.entity.Employee; @Repository public interface EmployeeRepository extends CrudRepository<Employee, Integer> { }
Service
Create a Service to call repository instance to perform database operations on Employee Object.
EmployeeService.java
package com.tutorialspoint.springbootorm.service; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.tutorialspoint.springbootorm.entity.Employee; import com.tutorialspoint.springbootorm.repository.EmployeeRepository; @Service public class EmployeeService { @Autowired EmployeeRepository repository; // get an employee by id public Employee getEmployeeById(int id) { return repository.findById(id).get(); } // get list of all employees public List<Employee> getAllEmployees(){ List<Employee> employees = new ArrayList<Employee>(); repository.findAll().forEach(employee -> employees.add(employee)); return employees; } // create or update an employee public void saveOrUpdate(Employee employee) { repository.save(employee); } // delete the employee public void deleteEmployeeById(int id) { repository.deleteById(id); } }
Controller
Create a controller for REST APIs.
EmployeeController.java
package com.tutorialspoint.springbootorm.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.tutorialspoint.springbootorm.entity.Employee; import com.tutorialspoint.springbootorm.service.EmployeeService; @RestController @RequestMapping(path = "/emp") public class EmployeeController { @Autowired EmployeeService employeeService; // GET mapping to get all the employees @GetMapping("/employees") public List<Employee> getAllEmployees(){ return employeeService.getAllEmployees(); } // GET mapping to get an employee by id @GetMapping("/employee/{id}") public Employee getEmployee(@PathVariable("id") int id) { return employeeService.getEmployeeById(id); } // DELETE mapping to delete an employee by id @DeleteMapping("/employee/{id}") public void deleteEmployee(@PathVariable("id") int id) { employeeService.deleteEmployeeById(id); } // POST mapping to create a new employee @PostMapping("/employee") public void addEmployee(@RequestBody Employee employee) { employeeService.saveOrUpdate(employee); } // PUT mapping to update an employee @PutMapping("/employee") public void updateEmployee(@RequestBody Employee employee) { employeeService.saveOrUpdate(employee); } }
Main Application
Main Application class to boot the application.
SpringBootOrmApplication.java
package com.tutorialspoint.springbootorm; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; // Main Application @SpringBootApplication public class SpringBootOrmApplication { public static void main(String[] args) { SpringApplication.run(SpringBootOrmApplication.class, args); } }
Spring Boot ORM - Test Project
Now in STS, right click on the springbootorm project, select Run As -> Spring Boot App context −
Output
You will similar result in STS Console.
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ [32m :: Spring Boot :: [39m [2m (v3.3.3)[0;39m [2m2024-08-28T15:38:41.453+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mc.t.s.SpringbootormApplication [0;39m [2m:[0;39m Starting SpringbootormApplication using Java 21.0.3 with PID 4760 (E:\springbootorm\target\classes started by Tutorialspoint in E:\springbootorm) [2m2024-08-28T15:38:41.456+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mc.t.s.SpringbootormApplication [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default" [2m2024-08-28T15:38:41.517+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable [2m2024-08-28T15:38:41.517+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' [2m2024-08-28T15:38:42.164+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Bootstrapping Spring Data JPA repositories in DEFAULT mode. [2m2024-08-28T15:38:42.214+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Finished Spring Data repository scanning in 43 ms. Found 1 JPA repository interface. [2m2024-08-28T15:38:42.781+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port 8080 (http) [2m2024-08-28T15:38:42.797+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat] [2m2024-08-28T15:38:42.797+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/10.1.28] [2m2024-08-28T15:38:42.848+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext [2m2024-08-28T15:38:42.848+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 1330 ms [2m2024-08-28T15:38:42.969+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Starting... [2m2024-08-28T15:38:43.457+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mcom.zaxxer.hikari.pool.HikariPool [0;39m [2m:[0;39m HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@3c6da728 [2m2024-08-28T15:38:43.459+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Start completed. [2m2024-08-28T15:38:43.504+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.hibernate.jpa.internal.util.LogHelper [0;39m [2m:[0;39m HHH000204: Processing PersistenceUnitInfo [name: default] [2m2024-08-28T15:38:43.564+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36morg.hibernate.Version [0;39m [2m:[0;39m HHH000412: Hibernate ORM core version 6.5.2.Final [2m2024-08-28T15:38:43.600+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.h.c.internal.RegionFactoryInitiator [0;39m [2m:[0;39m HHH000026: Second-level cache disabled [2m2024-08-28T15:38:43.934+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.s.o.j.p.SpringPersistenceUnitInfo [0;39m [2m:[0;39m No LoadTimeWeaver setup: ignoring JPA class transformer [2m2024-08-28T15:38:44.909+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.h.e.t.j.p.i.JtaPlatformInitiator [0;39m [2m:[0;39m HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration) Hibernate: create table employee (id integer not null auto_increment, age integer not null, email varchar(255), name varchar(255), primary key (id)) engine=InnoDB [2m2024-08-28T15:38:45.141+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Initialized JPA EntityManagerFactory for persistence unit 'default' [2m2024-08-28T15:38:45.431+05:30[0;39m [33m WARN[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mJpaBaseConfiguration$JpaWebConfiguration[0;39m [2m:[0;39m spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning [2m2024-08-28T15:38:45.862+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.s.b.d.a.OptionalLiveReloadServer [0;39m [2m:[0;39m LiveReload server is running on port 35729 [2m2024-08-28T15:38:45.901+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port 8080 (http) with context path '/' [2m2024-08-28T15:38:45.909+05:30[0;39m [32m INFO[0;39m [35m4760[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mc.t.s.SpringbootormApplication [0;39m [2m:[0;39m Started SpringbootormApplication in 4.891 seconds (process running for 5.804)
Add an Employee
Once server is up and running, Use Postman to make a POST request to add a record first.
Set the following parameters in POSTMAN.
HTTP Method − POST
URL − http://localhost:8080/emp/employee
BODY − An employee JSON
{ "age": "35", "name": "Julie", "email": "julie@gmail.com" }
Click on Send Button and check the response status to be OK.

Get all Employees
Now make a GET Request to get all records.
Set the following parameters in POSTMAN.
HTTP Method − GET
URL − http://localhost:8080/emp/employees
Click the send button and verify the response.
[{ "id": 1, "age": 35, "name": "Julie", "email": "julie@gmail.com" }]

Spring Boot ORM - EclipseLink Integration
Spring Boot by default use Hibernate as ORM implementation. In order to use EclipseLink, we first need to exclude hibernate dependencies from spring-data-jpa dependency in pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </exclusion> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </exclusion> </exclusions> </dependency>
Now include eclipse−link dependency in pom.xml.
<dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa</artifactId> <version>4.0.4</version> </dependency>
Following is the complete pom.xml
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.tutorialspoint</groupId> <artifactId>springbootorm</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springbootorm</name> <description>Demo project for Spring Boot ORM</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>21</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </exclusion> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa</artifactId> <version>4.0.4</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
Save the file and eclipse will update the dependencies automatically.
Spring Boot ORM - Update Project EclipseLink
Spring Boot uses HibernateJpaAutoConfiguration which configures the hibernate implementation by default. In order to switch to EclipseLink, we need to create a custom configuration class which will extend the JpaBaseConfiguration class. JpaBaseConfiguration is the base class which is used to extend and configure JPA for any ORM implementation. Following is the code of EclipsLinkJpaConfiguration.
JPA Configuration
Create EclipseLink Configuration class.
EclipsLinkJpaConfiguration.java
package com.tutorialspoint.springbootorm; import java.util.HashMap; import java.util.Map; import javax.sql.DataSource; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.eclipse.persistence.logging.SessionLog; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter; import org.springframework.transaction.jta.JtaTransactionManager; // EclipseLink Specific Configuration Class @Configuration public class EclipsLinkJpaConfiguration extends JpaBaseConfiguration { protected EclipsLinkJpaConfiguration(DataSource dataSource, JpaProperties properties, ObjectProvider<JtaTransactionManager> jtaTransactionManager) { super(dataSource, properties, jtaTransactionManager); } // EclipseLink JPA Adaptor @Override protected AbstractJpaVendorAdapter createJpaVendorAdapter() { return new EclipseLinkJpaVendorAdapter(); } // EclipseLink Properties @Override protected Map<String, Object> getVendorProperties() { Map<String, Object> map = new HashMap<>(); map.put(PersistenceUnitProperties.WEAVING, "false"); map.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL); map.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_ONLY); map.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL); return map; } // Database Connection properties setup @Bean public static DataSource dataSource() { final DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/tutorialspoint"); dataSource.setUsername("root"); dataSource.setPassword("root@123"); return dataSource; } }
We've added Adapter, DataSource and properties using createJpaVendorAdapter(), dataSource() and getVendorProperties() methods respectively.
Update Entity
Update the Entity as well to use Integer instead of int.
Employee.java
package com.tutorialspoint.springbootorm.entity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; // entity class to persist object to Employee Table @Entity public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String name; private Integer age; private String email; // setter, getter methods public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
Spring Boot ORM - Test EclipseLink
Now in STS, right click on the springbootorm project, select Run As -> Spring Boot App context −
Output
You will similar result in STS Console.
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ [32m :: Spring Boot :: [39m [2m (v3.3.3)[0;39m [2m2024-08-29T09:27:56.504+05:30[0;39m [32m INFO[0;39m [35m4004[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mc.t.s.SpringbootormApplication [0;39m [2m:[0;39m Starting SpringbootormApplication using Java 21.0.3 with PID 4004 (E:\springbootorm\target\classes started by Tutorialspoint in E:\springbootorm) ... [EL Config]: metadata: 2024-08-29 09:28:00.503--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--The alias name for the entity class [class com.tutorialspoint.springbootorm.entity.Employee] is being defaulted to: Employee. [EL Config]: metadata: 2024-08-29 09:28:00.508--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--The table name for entity [class com.tutorialspoint.springbootorm.entity.Employee] is being defaulted to: EMPLOYEE. [EL Config]: metadata: 2024-08-29 09:28:00.528--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--The column name for element [name] is being defaulted to: NAME. [EL Config]: metadata: 2024-08-29 09:28:00.533--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--The column name for element [id] is being defaulted to: ID. [EL Config]: metadata: 2024-08-29 09:28:00.534--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--The column name for element [age] is being defaulted to: AGE. [EL Config]: metadata: 2024-08-29 09:28:00.535--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--The column name for element [email] is being defaulted to: EMAIL. [EL Finer]: metamodel: 2024-08-29 09:28:00.567--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--Canonical Metamodel class [com.tutorialspoint.springbootorm.entity.Employee_] not found during initialization. [2m2024-08-29T09:28:00.568+05:30[0;39m [32m INFO[0;39m [35m4004[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Initialized JPA EntityManagerFactory for persistence unit 'default' [EL Finer]: 2024-08-29 09:28:00.634--Thread(Thread[#38,restartedMain,5,main])--initializing session manager [EL Info]: 2024-08-29 09:28:00.638--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--EclipseLink, version: Eclipse Persistence Services - 4.0.4.v202407190748-059428cdd2583c46f1f3e50d235854840a6fa9a7 [EL Fine]: connection: 2024-08-29 09:28:01.166--Thread(Thread[#38,restartedMain,5,main])--Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform [EL Fine]: connection: 2024-08-29 09:28:01.179--ServerSession(46117356)--Connection(2116562590)--Thread(Thread[#38,restartedMain,5,main])--connecting(DatabaseLogin( platform=>MySQLPlatform user name=> "" connector=>JNDIConnector datasource name=>null )) [EL Config]: connection: 2024-08-29 09:28:01.225--ServerSession(46117356)--Connection(1122916129)--Thread(Thread[#38,restartedMain,5,main])--Connected: jdbc:mysql://localhost:3306/tutorialspoint User: root@localhost Database: MySQL Version: 8.0.39 Driver: MySQL Connector/J Version: mysql-connector-j-8.3.0 (Revision: 805f872a57875f311cb82487efcfb070411a3fa0) [EL Fine]: connection: 2024-08-29 09:28:01.226--ServerSession(46117356)--Connection(610477732)--Thread(Thread[#38,restartedMain,5,main])--connecting(DatabaseLogin( platform=>MySQLPlatform user name=> "" connector=>JNDIConnector datasource name=>null )) [EL Config]: connection: 2024-08-29 09:28:01.253--ServerSession(46117356)--Connection(1814465297)--Thread(Thread[#38,restartedMain,5,main])--Connected: jdbc:mysql://localhost:3306/tutorialspoint User: root@localhost Database: MySQL Version: 8.0.39 Driver: MySQL Connector/J Version: mysql-connector-j-8.3.0 (Revision: 805f872a57875f311cb82487efcfb070411a3fa0) [EL Fine]: connection: 2024-08-29 09:28:01.29--ServerSession(46117356)--Thread(Thread[#38,restartedMain,5,main])--/file:/E:/springbootorm/target/classes/_default login successful ... [2m2024-08-29T09:28:02.343+05:30[0;39m [32m INFO[0;39m [35m4004[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.s.b.d.a.OptionalLiveReloadServer [0;39m [2m:[0;39m LiveReload server is running on port 35729 [2m2024-08-29T09:28:02.377+05:30[0;39m [32m INFO[0;39m [35m4004[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port 8080 (http) with context path '/' [2m2024-08-29T09:28:02.385+05:30[0;39m [32m INFO[0;39m [35m4004[0;39m [2m---[0;39m [2m[springbootorm] [ restartedMain][0;39m [2m[0;39m[36mc.t.s.SpringbootormApplication [0;39m [2m:[0;39m Started SpringbootormApplication in 6.895 seconds (process running for 8.546)
Get all Employees
Now make a GET Request to get all records.
Set the following parameters in POSTMAN.
HTTP Method − GET
URL − http://localhost:8080/emp/employees
Click the send button and verify the response.
[{ "id": 1, "age": 35, "name": "Julie", "email": "julie@gmail.com" }]

You will see similar updates in STS Console as well.
[EL Finer]: connection: 2024-08-29 09:31:20.416--ServerSession(46117356)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--client acquired: 1215821283 [EL Finer]: transaction: 2024-08-29 09:31:20.43--ClientSession(1215821283)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--acquire unit of work: 2007319936 [EL Finer]: transaction: 2024-08-29 09:31:20.498--UnitOfWork(2007319936)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--begin unit of work flush [EL Finer]: transaction: 2024-08-29 09:31:20.498--UnitOfWork(2007319936)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--end unit of work flush [EL Fine]: sql: 2024-08-29 09:31:20.55--ServerSession(46117356)--Connection(135997463)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--SELECT ID, AGE, EMAIL, NAME FROM EMPLOYEE [EL Finer]: transaction: 2024-08-29 09:31:20.599--UnitOfWork(2007319936)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--begin unit of work commit [EL Finer]: transaction: 2024-08-29 09:31:20.599--UnitOfWork(2007319936)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--end unit of work commit [EL Finer]: transaction: 2024-08-29 09:31:20.599--UnitOfWork(2007319936)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--resume unit of work [EL Finer]: transaction: 2024-08-29 09:31:20.731--UnitOfWork(2007319936)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--release unit of work [EL Finer]: connection: 2024-08-29 09:31:20.731--ClientSession(1215821283)--Thread(Thread[#50,http-nio-8080-exec-1,5,main])--client released