Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

jpa-with-hibernate

> 编程语言
Open source

Master JPA using Hibernate as the implementation. Learn the basics of JPA - entities, relationships, entity manager, annotations, JPQL and Criteria API. Take a

699 stars0 likes0 views
WebsiteGitHub

About

Master JPA using Hibernate as the implementation. Learn the basics of JPA - entities, relationships, entity manager, annotations, JPQL and Criteria API. Take a

Master JPA and Hibernate with Spring Boot

Master JPA using Hibernate as the implementation. Learn the basics of JPA - entities, relationships, entity manager, annotations, JPQL and Criteria API. Take a step into the advanced world of JPA - caching, performance tuning(n + 1 queries), mapping inheritance hierarchies. Get a peek into the magic of Spring Data JPA & Spring Data Rest.

Overview

  • Installing Eclipse, Maven and Java
  • Running Examples
  • Course Overview
    • Course Steps
    • Expectations
  • About in28Minutes
    • Our Beliefs
    • Our Approach
    • Find Us
    • Other Courses

Introduction

The Java Persistence API provides Java developers with an api for mapping java objects to relational data. In this course, you will learn about the JPA API, JPQL (Java Persistence query language), Java Persistence Criteria API and how you can perform ORM (Object Relational Mapping) with JPA.

Hibernate is the most popular implementation of JPA. It was the most popular ORM framework option before JPA emerged, and it provides additional features on top of JPA. We will use Hibernate as the implementation in this course.

What You will learn

  • You will learn the basics of JPA and Hibernate - Entities, Relationships, Inheritance Mappings and Annotations
  • You will understand approaches to querying data using JPA and Hibernate - JPQL, Criteria API and Native Queries
  • You will understand JPA and Hibernate Relationships in depth – One to One, Many to One and Many to Many
  • You will use a variety of Spring Boot Starters – Spring Boot Starter Web, Starter Data Jpa, Starter Test
  • You will learn the basics of performance tuning your JPA application with Hibernate - Solve N+1 Queries Issue.
  • You will learn the basics of caching – First Level Cache and Second Level Cache with EhCache
  • You will understand the basics of Spring Data JPA and Spring Data REST

Requirements

  • You should have working knowledge of Java and Annotations.
  • We will help you install Eclipse and get up and running with Maven and Tomcat.

Step Wise Details

Refer to each section

Connecting to My SQL and Other Databases

Spring Boot makes it easy to switch databases! Yeah really simple.

Steps

  • Install MySQL and Setup Schema
  • Remove H2 dependency from pom.xml
  • Add MySQL (or your database) dependency to pom.xml
xml

    com.mysql
    mysql-connector-j
    runtime
  • Configure application.properties
properties
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/person_example
spring.datasource.username=personuser
spring.datasource.password=YOUR_PASSWORD
  • Restart the app and You are ready!

Spring Boot can set up the database for you using Hibernate

Things to note:

  • Spring Boot chooses a default value for you based on whether it thinks your database is embedded (default create-drop) or not (default none).
  • spring.jpa.hibernate.ddl-auto is the setting to perform SchemaManagementTool actions automatically
    • none: No action will be performed.
    • create-only: Database creation will be generated.
    • drop: Database dropping will be generated.
    • create: Database dropping will be generated followed by database creation.
    • validate: Validate the database schema
    • update: Update the database schema
  • Reference: https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl

application.properties

#none, validate, update, create, create-drop
spring.jpa.hibernate.ddl-auto=create

Installing and Setting Up MySQL

  • Install MySQL https://dev.mysql.com/doc/en/installing.html
    • More details - http://www.mysqltutorial.org/install-mysql/
    • Trouble Shooting - https://dev.mysql.com/doc/refman/en/problems.html
  • Start up the Server (as a service)
  • Go to the command prompt (or terminal)
    • Execute the following commands to create a database and a user
mysql --user=user_name --password db_name
create database person_example;
create user 'personuser'@'localhost' identified by 'YOUR_PASSWORD';
grant all on person_example.* to 'personuser'@'localhost';
  • Execute the following SQL queries to create the table and insert the data

JDBC TO JPA

Table

sql
create table person
(
  id integer not null,
  birth_date timestamp,
  location varchar(255),
  name varchar(255),
  primary key (id)
);

Data

sql
INSERT INTO PERSON (ID, NAME, LOCATION, BIRTH_DATE ) VALUES(10001,  'Ranga', 'Hyderabad',sysdate());
INSERT INTO PERSON (ID, NAME, LOCATION, BIRTH_DATE ) VALUES(10002,  'James', 'New York',sysdate());
INSERT INTO PERSON (ID, NAME, LOCATION, BIRTH_DATE ) VALUES(10003,  'Pieter', 'Amsterdam',sysdate());

JPA in Depth

Tables

…

Data

…

Installing Tools

  • Installation Video : https://www.youtube.com/playlist?list=PLBBog2r6uMCSmMVTW_QmDLyASBvovyAO3
  • GIT Repository For Installation : https://github.com/in28minutes/getting-started-in-5-steps
  • PDF : https://github.com/in28minutes/SpringIn28Minutes/blob/master/InstallationGuide-JavaEclipseAndMaven_v2.pdf

Running Examples

  • Download the zip or clone the Git repository.
  • Unzip the zip file (if you downloaded one)
  • Open Command Prompt and Change directory (cd) to the folder containing pom.xml
  • Open Eclipse
    • File → Import → Existing Maven Project → Navigate to the folder where you unzipped the zip
    • Select the right project
  • Choose the Spring Boot Application file (search for @SpringBootApplication)
  • Right-Click on the file and Run as Java Application
  • You are all Set
  • For help: use our installation guide – https://www.youtube.com/playlist?list=PLBBog2r6uMCSmMVTW_QmDLyASBvovyAO3

Troubleshooting

  • Refer our TroubleShooting Guide - https://github.com/in28minutes/in28minutes-initiatives/tree/master/The-in28Minutes-TroubleshootingGuide-And-FAQ

YouTube Playlists - 500+ Videos

Click here - 30+ Playlists with 500+ Videos on Spring, Spring Boot, REST, Microservices and the Cloud

Keep Learning in28Minutes

in28Minutes is creating amazing solutions for you to learn Spring Boot, Full Stack and the Cloud – Docker, Kubernetes, AWS, React, Angular, etc. - Check out all our courses here

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Java

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言