0
嘿,我正在學習這個東西,我不完全理解它,我有一個問題,我不知道在persistence.xml中提供者標記中寫什麼如何配置persistence.xml提供程序標記
這裏是我的persistence.xml和pom.xml的文件:
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.jpa</groupId>
<artifactId>JPAProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
</dependencies>
<build>
<finalName>JPAProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</build>
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
<persistence-unit name="Database" transaction-type="RESOURCE_LOCAL">
<class>models.Employee</class>
<provider>WHAT TO WRITE HERE ?</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/jpa"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
所以我必須添加一個依賴以使用org.hibernate.ejb.HibernatePersistence爲例?我試過它,它的工作原理,唯一的問題是,它說,HibernatePersistence已被棄用。我應該使用什麼,而不是從休眠狀態? – Greyshack
你可以在你的提供者中直接使用'HibernatePersistenceProvider'。請參閱API文檔:http://docs.jboss.org/hibernate/orm/5.0/javadocs/org/hibernate/ejb/HibernatePersistence.html –
此標記是可選的。 –
karlihnos