问题
Hey I'm learning this stuff, I don't really understand all of it and I have a problem, I don't know what to write in provider tag in persistence.xml
Here are my persistence.xml and pom.xml files:
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>
回答1:
In provider
tag you need to include vendor specific PersistenceProvider
implementation.
Please refer this discussion; you may get idea about this.
Answer to your question:-
If you wanted to use Eclipselink implementation of JPA please use provider
tag like below--
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
OR
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
for Hibernet implementation of JPA.
来源:https://stackoverflow.com/questions/31673548/how-to-configure-persistence-xml-provider-tag