- Spring ORM Tutorial
- Spring ORM - Home
- Spring ORM - Overview
- Spring ORM - Environment Setup
- Spring ORM & Hibernate
- Spring ORM - Create Project
- Spring ORM - Maven Hibernate
- Spring ORM - Persistence Hibernate
- Spring ORM - Update Project
- Spring ORM - Run & Test Hibernate
- Spring ORM & EclipseLink
- Spring ORM - Maven EclipseLink
- Spring ORM - Persistence EclipseLink
- Spring ORM - Update Project EclipseLink
- Spring ORM - Run & Test EclipseLink
- Spring ORM Useful Resources
- Spring ORM - Quick Guide
- Spring ORM - Useful Resources
- Spring ORM - Discussion
Spring ORM - Persistence Hibernate
persistence.xml defines the various aspects related to hibernate like following.
Persistence Unit − A persistence unit containing all the details. It's name is used to get reference in spring context.
provider − org.hibernate.jpa.HibernatePersistenceProvider class will be used as provider.
Database url and credentials − In properties section, we pass the database related values.
show_sql − to show the generated sql queries
hbm2ddl − to allow hibernate to create tables.
Create persistence.xml in src -> main > resources > META-INF folder.
persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> <persistence-unit name="Hibernate_JPA"> <description> Spring Hibernate JPA Configuration Example</description> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" /> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false" /> <property name="javax.persistence.jdbc.user" value="root" /> <property name="javax.persistence.jdbc.password" value="root@123" /> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.hbm2ddl.auto" value="create" /> </properties> </persistence-unit> </persistence>
Advertisements
To Continue Learning Please Login
Login with Google