Publish Your Article Here

Spring Data JPA with Spring Boot Applications - Oracle - example

This page gives an example to configure Spring Boot application with Spring Data JPA.

Include below dependencies in your pom.xml file:

1) spring-boot-starter-data-jpa

2) Oracle Driver (ojdbc7.jar)

3) HikariCP 2.6 (to maintain connection pool)

Here is the example pom.xml for your reference:

<project xmlns="" xmlns:xsi=""



	    <!-- include Spring data JPA dependencies, exclude default tomcat pool-->
        <!-- Oracle JDBC driver -->

        <!-- HikariCP connection pool -->

			<!-- Package as an executable jar/war -->

Entity Class - Employee

Employee Class
package com.java2novice.springboot.models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

public class Employee {

    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "emp_seq")
    @SequenceGenerator(sequenceName = "emp_seq", allocationSize = 1, name = "emp_seq")
	@Column(name = "emp_id")
    private Long empId;

	private String name;

	private Integer age;

	private Integer salary;

	public Long getEmpId() {
		return empId;

	public void setEmpId(Long empId) {
		this.empId = empId;

	public String getName() {
		return name;

	public void setName(String name) { = name;

	public Integer getAge() {
		return age;

	public void setAge(Integer age) {
		this.age = age;

	public Integer getSalary() {
		return salary;

	public void setSalary(Integer salary) {
		this.salary = salary;

You can have your DB datasource related configurations at file as shown below:
# Oracle DB Settings

# HikariCP settings


Create Spring Data CrudRepository:

package com.java2novice.springboot.dao;

import java.util.List;


import com.java2novice.springboot.models.Employee;

public interface EmployeeDao extends CrudRepository<Employee, Long>{

	List<Employee> findByName(String name);

Spring Boot Starter

package com.java2novice.springboot;

import javax.sql.DataSource;
import org.springframework.transaction.annotation.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.java2novice.springboot.dao.EmployeeDao;

public class SpringBootWebApplication implements CommandLineRunner{

	private static Logger logger = LoggerFactory.getLogger(SpringBootWebApplication.class);

    private DataSource dataSource;

	private EmployeeDao employeeDao;

	public static void main(String[] args) throws Exception {, args);

	@Transactional(readOnly = true)
    public void run(String... args) throws Exception {

<< Previous Program | Next Program >>

Spring-Boot Examples

  1. Spring-Boot initial setup.
  2. Spring-Boot hello world example
  3. What is spring-boot-starter-parent in Spring-Boot pom.xml file?
  4. What is @SpringBootApplication annotation in spring boot?
  5. What is in spring boot?
  6. What is @ConfigurationProperties annotation in spring boot?
  7. Spring Boot @ConfigurationProperties example
  8. Spring Boot @ConfigurationProperties Property Validation
  9. Difference between @ConfigurationProperties and @Value
  10. Spring boot web application configurations.
  11. How to run spring boot application through command line?
  12. How to run spring boot as a standalone application (non-web)?
  13. Spring boot property resolution order.
  14. Spring Boot – Profile based properties example.
  15. How to configure logback (SLF4J) logging to spring boot applications?
  16. How to update application context path in spring boot?
  17. How to disable spring logo banner in spring boot?
  18. Spring Data JPA with Spring Boot Applications - Oracle - example
  19. Spring Data JPA with Spring Boot Applications - MySql example
  20. How to configure Spring Boot to show Hibernate SQL Query in logs?
  21. Spring Boot – List all Beans loaded in the ApplicationContext
  22. How to load external property files into Spring Boot application?
  23. How to rename file in Spring Boot application?
  24. How to configure multiple DataSources (Databases) with Spring Boot and Spring Data?
Java2Novice - YouTube Channel
  1. Python Tutorial for Beginners
Knowledge Centre
wait Vs sleep methods
sleep(): It is a static method on Thread class. It makes the current thread into the "Not Runnable" state for specified amount of time. During this time, the thread keeps the lock (monitors) it has acquired.

wait(): It is a method on Object class. It makes the current thread into the "Not Runnable" state. Wait is called on a object, not a thread. Before calling wait() method, the object should be synchronized, means the object should be inside synchronized block. The call to wait() releases the acquired lock.
Famous Quotations
I respect faith, but doubt is what gets you an education.
-- Wilson Mizner

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2019 by Nataraja Gootooru. All Rights Reserved.