我遇到了使用JPA注释运行我的java程序的问题。它看起来我没有正确设置环境。这是我的错误消息:
这是我的项目结构:
这是我的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。我感到困惑的一件事是在建议中设置类路径。任何人都可以给我一个提示吗?我很感激。
萨姆
答案 0 :(得分:0)
您已指定提供商
<provider>org.hibernate.ejb.HibernatePersistence</provider>
但是你没有在类路径中有HibernatePersistence
类的jar。该类位于相应版本的Beaker harness yum repos jar中。
您只需将hibernate-entitymanager
添加到pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.core.version}</version>
</dependency>