Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
persistence xml configurations for major databases and jpa providers
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<!-- derby -->
<persistence-unit name="derby">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="com.mysema.query.jpa.support.ExtendedDerbyDialect" />
<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="hibernate.connection.url" value="jdbc:derby:target/derbydb;create=true" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" /> -->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
<persistence-unit name="derby-eclipselink"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:target/derbydb2;create=true" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
<persistence-unit name="derby-openjpa"
transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:target/derbydb3;create=true" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" /> -->
</properties>
</persistence-unit>
<!-- hsqldb -->
<persistence-unit name="hsqldb">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="com.mysema.query.jpa.support.ExtendedHSQLDialect" />
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
<property name="hibernate.connection.url" value="jdbc:hsqldb:file:target/testdb;shutdown=true" />
<property name="hibernate.connection.user" value="sa" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" /> -->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
<persistence-unit name="hsqldb-eclipselink"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:file:target/testdb2;shutdown=true" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
<!-- h2 -->
<persistence-unit name="h2" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:target/h2-1" />
<property name="hibernate.connection.user" value="sa" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />-->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
<persistence-unit name="h2-eclipselink"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:target/h2-2" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
<persistence-unit name="h2-openjpa" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:target/h2-3" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database"
/> -->
</properties>
</persistence-unit>
<!-- mysql -->
<persistence-unit name="mysql">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/querydsl" />
<property name="hibernate.connection.username" value="querydsl" />
<property name="hibernate.connection.password" value="querydsl" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />-->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
<persistence-unit name="mysql-eclipselink"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/querydsl" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
<!-- postgres -->
<persistence-unit name="postgres">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/querydsl" />
<property name="hibernate.connection.username" value="querydsl" />
<property name="hibernate.connection.password" value="querydsl" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />-->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
<!-- oracle -->
<persistence-unit name="oracle">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="com.mysema.query.jpa.support.ExtendedOracleDialect" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="hibernate.connection.username" value="querydsl" />
<property name="hibernate.connection.password" value="querydsl" />
<!-- <property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />-->
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
@Java-Adore

This comment has been minimized.

Copy link

@Java-Adore Java-Adore commented Jan 2, 2015

thanks

@lduparc

This comment has been minimized.

Copy link

@lduparc lduparc commented May 12, 2015

Thanks

@altitdb

This comment has been minimized.

Copy link

@altitdb altitdb commented May 14, 2015

Thanks very much!!

@JeromeBosman

This comment has been minimized.

Copy link

@JeromeBosman JeromeBosman commented May 25, 2015

thanks!

@danglong81

This comment has been minimized.

Copy link

@danglong81 danglong81 commented Jul 18, 2015

thanks

@chibenwa

This comment has been minimized.

Copy link

@chibenwa chibenwa commented Oct 3, 2015

Whao, cool ! Thanks

@Startouf

This comment has been minimized.

Copy link

@Startouf Startouf commented Jan 2, 2016

SQLite ?

@hima4rill

This comment has been minimized.

Copy link

@hima4rill hima4rill commented May 19, 2016

Thanks Man

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 1, 2016

Thanks a lot B-)

@priyanshu-agarwal1

This comment has been minimized.

Copy link

@priyanshu-agarwal1 priyanshu-agarwal1 commented Aug 26, 2016

thanks

@DaniilSolovyov

This comment has been minimized.

Copy link

@DaniilSolovyov DaniilSolovyov commented Feb 19, 2017

You are best)

@danilogprojetos

This comment has been minimized.

Copy link

@danilogprojetos danilogprojetos commented Mar 15, 2017

Thanks!!

@rusakovichma

This comment has been minimized.

Copy link

@rusakovichma rusakovichma commented Mar 20, 2017

thanks

@joaolbl

This comment has been minimized.

Copy link

@joaolbl joaolbl commented May 11, 2017

Thanks a lot!

@moxim

This comment has been minimized.

Copy link

@moxim moxim commented May 12, 2017

great stuff, thanks!
my fork added postgres-eclipslink

@nimo23

This comment has been minimized.

Copy link

@nimo23 nimo23 commented May 24, 2017

I cannot find "hibernate.flushMode" in official docs http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html. Depreciated?

<property name="hibernate.flushMode" value="FLUSH_AUTO" />

would be nice to update your settings to jpa 2.1 (or hibernate 5)

@karenworld

This comment has been minimized.

Copy link

@karenworld karenworld commented Jul 28, 2017

thanks

@ekkapongs

This comment has been minimized.

Copy link

@ekkapongs ekkapongs commented Jul 29, 2017

Very Thank you

@mudassir047

This comment has been minimized.

Copy link

@mudassir047 mudassir047 commented Nov 28, 2017

MariaDB?

@cancastilho

This comment has been minimized.

Copy link

@cancastilho cancastilho commented Apr 5, 2018

Thank you very much.

@owen800q

This comment has been minimized.

Copy link

@owen800q owen800q commented Feb 13, 2019

thank you, very helpful

@Celludriel

This comment has been minimized.

Copy link

@Celludriel Celludriel commented May 14, 2019

Very helpfull !

@seycileli

This comment has been minimized.

Copy link

@seycileli seycileli commented Jan 23, 2020

Amazing post, thank you!

forked!

@seycileli

This comment has been minimized.

Copy link

@seycileli seycileli commented Jan 24, 2020

Amazing post, thank you!

forked!

Hi @mortezaadi!

For anyone using Hibernate and is getting an error message that says

cannot resolve package

Try the below, it worked for me

    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
@mortezaadi

This comment has been minimized.

Copy link
Owner Author

@mortezaadi mortezaadi commented Mar 31, 2020

Thanks @seycileli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment