JPA + Hibernate获取NoSuchFieldError

时间:2012-08-17 00:00:57

标签: java hibernate jpa

我变得很奇怪java.lang.NoSuchFieldError:尝试将JPA与Oracle DB一起使用的NONE运行时错误。我正在使用Maven构建。这是关键文件。我猜测某些JAR存在问题。

pox.xml

    <dependency>
              <groupId>javax.persistence</groupId>
              <artifactId>persistence-api</artifactId>
              <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.5.6-Final</version>
    </dependency>

的persistence.xml

   <persistence-unit name="ifp-test" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
         <property name="javax.persistence.jdbc.user" value="something"/>
         <property name="javax.persistence.jdbc.password" value="something"/>
          <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin://@something_here"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      </properties>
   </persistence-unit>
</persistence>

Java代码

    List arr_cust = entityManagerFactory.createEntityManager().createNativeQuery(sql_query).getResultList();

有人可以指出正确的方向吗?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。问题出在pom.xml中。这是正确的pom.xml。

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.5.6-Final</version>
</dependency>