3

我是使用 EclipseLink JPA 开发的新手,我正在使用 eclipselink-2.4.0.v20120608-r11652.zip 这个版本。我的问题的全部故事是我的库包含一些 JPA 1.0 库,我决定通过下载上面的最新 EclipseLink 升级到 JPA 2.0,通过调整顺序以将这些最新库加载到第一个,我的代码可以使用最新的类从正确的库,

一旦我开始运行,createEntityManagerFactory 上的代码错误,抱怨它需要我刚刚摆脱的 datanucleus-api.jar 中的类。这是堆栈跟踪:

java.lang.NoClassDefFoundError: org/datanucleus/jpa/exceptions/NoPersistenceXmlException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at core.server.jpa.RawTrades.testMethod(RawTrades.java:18)
at test.testJPA.testMethod(testJPA.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:21)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:194)

我的代码是下面的标准代码

private static final String PERSISTENCE_UNIT_NAME = "SimTool";
  private static EntityManagerFactory factory;

public static void testMethod() {
    factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,new HashMap());
    EntityManager em = factory.createEntityManager();
}

我的 persistence.xml 站点位于 /WEB-INFO/classes/META-INFO/persistence.xml,有趣的是我将它设置为进行日志记录,但根本没有生成日志文件。

 <?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="SimTool" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>core.server.jpa.RawTrade</class>
<class>core.shared.Schedule</class>
<properties>
  <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
  <property name="javax.persistence.jdbc.url"
    value="jdbc:sqlserver://gprimesqldb1u.eur.nsroot.net:2431;databasename=GlobalPrimeDb" />
  <property name="javax.persistence.jdbc.user" value="NoSafeToShare" />
  <property name="javax.persistence.jdbc.password" value="OnlyDeterminedOneWillGetIt" />

  <!-- EclipseLink should create the database schema automatically -->
  <property name="eclipselink.ddl-generation" value="create-tables" />
  <property name="eclipselink.ddl-generation.output-mode" value="both" />
  <property name="eclipselink.logging.file" value="JPAoutput.log"/>
  <property name="eclipselink.logging.logger" value="JavaLogger"/>
  <property name="eclipselink.logging.level" value="FINE" />
</properties>

我觉得代码仍在尝试加载旧的 JPA 库而不是 EclipseLink 库,非常感谢您的帮助

4

1 回答 1

1

datanucleus添加到您的 WEB-INF 或运行时类路径。

于 2012-09-11T11:33:30.333 回答