0
我遇到運行我的JPA註解java程序的問題。它看起來我沒有正確設置環境。這是我的錯誤信息:錯誤消息:沒有找到EntityManager的持久性提供者命名爲
這裏是我的項目結構:
這裏是我的persistence.xml
<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_2_0.xsd"
version="2.0">
<persistence-unit name="IFP" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>gov.faa.infra.ifp.ifp_hibernate_test.ProcSegment</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<validation-mode>NONE</validation-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
<property name="hibernate.archive.autodetection" value="class, htm" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.transaction.flush_before_completion" value="true" />
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@jamcdfdndb500.amc.faa.gov:1521:dnavln"/>
<property name="url" value="jdbc:oracle:thin:@jamcdfdndb500.amc.faa.gov:1521:dnavln" />
<property name="javax.persistence.jdbc.user" value="xxxxxx"/>
<property name="javax.persistence.jdbc.password" value="xxxxxx"/>
<property name="javax.persistence.query.timeout" value="1000000"/>
</properties>
</persistence-unit>
</persistence>
這裏是我的代碼來創建實體經理:
package gov.faa.infra.ifp.ifp_hibernate_test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class AccessHibernateTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
EntityManagerFactory entityManagerfactory = Persistence.createEntityManagerFactory("IFP");
EntityManager entityManager= entityManagerfactory.createEntityManager();
entityManager.getTransaction().begin();
ProcId procId=new ProcId(6688L, 1, "C", new Integer(0));
ProcSegment procSegment=entityManager.find(ProcSegment.class, procId);
System.out.println(procSegment.toString());
entityManager.getTransaction().commit();
}
}
這裏是我的pom.xml:
<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>gov.faa.infra.ifp</groupId>
<artifactId>ifp-hibernate-test</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>ifp-hibernate-test</name>
<url>http://maven.apache.org</url>
<properties>
<hibernate.core.version>3.6.10.Final</hibernate.core.version>
<junit.version>4.6</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.core.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>siap</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>build.txt</include>
<include>log4j.properties</include>
<include>siap.properties</include>
<include>correlation.properties</include>
<include>META-INF/persistence.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerArguments>
<extdirs>${basedir}/src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/webapp/WEB-INF/lib/restlet-2.0m3.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
</project>
我試圖建立環境,過去的職位建議,但它沒有工作,我使用Eclipse。我感到困惑的一件事是在建議中設置課程路徑。任何人都可以給我一個提示嗎?我會很感激。
山姆
[爲EntityManager的不持久性提供者命名]的可能的複製(http://stackoverflow.com/questions/1158159/no-persistence-provider-for -entitymanager命名) – Arpit