sample: persistence.xml
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" 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"> <persistence-unit name="pu" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mysql"/> <property name="javax.persistence.jdbc.user" value="tyson"/> <property name="javax.persistence.jdbc.password" value="tyson"/> <property name = "hibernate.show_sql" value = "true" /> <property name = "hibernate.format_sql" value = "true" /> <property name = "hibernate.hbm2ddl.auto" value = "none" /> <property name = "hibernate.dilect" value = "org.hibernate.dialect.MySQLDialect" /> </properties> </persistence-unit> </persistence>
- persistence-unit
- unit for each db connection
- name
- Name to the connection
- transaction-type
- RESOURCE_LOCAL
- For Standalone projects
- JTA (Default)
- For JavaEE projects
- RESOURCE_LOCAL
- provider
- Name of the ORM framework you are using, in our case it is Hibernate
- class
- Name of the Entities listed here
- Properties
- javax.persistence.jdbc.driver
- JDCB Driver name
- javax.persistence.jdbc.url
- Connection URL
- javax.persistence.jdbc.user
- Username of DB
- javax.persistence.jdbc.password
- Password of DB
- hibernate.show_sql
- prints SQL executed
- hibernate.format_sql
- formats the SQL
- hibernate.hbm2ddl.auto
- validate: validate the schema, makes no changes to the database.
- update: update the schema.
- create: creates the schema, destroying previous data.
- create-drop: drop the schema when the SessionFactory is closed explicitly, typically when the application is stopped.
- none: does nothing with the schema, makes no changes to the database
- javax.persistence.jdbc.driver
Reference :