xml 主要数据库和jpa提供程序的持久性xml配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml 主要数据库和jpa提供程序的持久性xml配置相关的知识,希望对你有一定的参考价值。

<?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>

以上是关于xml 主要数据库和jpa提供程序的持久性xml配置的主要内容,如果未能解决你的问题,请参考以下文章

关于JPA的理解

JPA-MSAccess DB 的 EntityManager 没有持久性提供程序

jpa实例

创建没有 persistence.xml 配置文件的 JPA EntityManager

JPA Hibernate jpa spring data jpa

JPA XML 查询文件