3

I am new to developing with EclipseLink JPA, i am using eclipselink-2.4.0.v20120608-r11652.zip this version. the full story of my problem is that my lib contain some JPA 1.0 lib and i decide to upgrade to JPA 2.0 by download latest EclipseLink above, by adjust the ordering to load those latest lib to first, my code compile fine with the latest classes from the right lib,

Once i start running, the code fault on createEntityManagerFactory, complaint that it need the class in a datanucleus-api.jar i just get rid of. here is the stack trace:

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)

my code is standard code below

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();
}

my persistence.xml site at /WEB-INFO/classes/META-INFO/persistence.xml, interesting thing is i set it to do logging, but there are not log file generated at all.

 <?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>

i feel the code is still try to load old JPA lib instead of EclipseLink lib, Many Thanks for the help

Ben.Yan
  • 118
  • 4
  • 13
  • Try using the javax.persistence jar from EclipseLink instead of the one from DataNucleous. – Chris Sep 11 '12 at 17:56
  • 1
    sorry, above comment isn't helpful. The Persistence class tries to load all providers on the classpath, and then asks each one if they are the provider for the persistence unit. Chances are there is a a jar from DataNucleous containing a META-INF/services/javax.persistence.spi.PersistenceProvider file still on the classpath causing DataNucleous to be loaded as a provider even though some required classes missing. – Chris Sep 11 '12 at 18:21
  • Hi Chris, you comment above does lead to answer, I been nailing down the problem to GWT's AppEngine, those datanucleus lib is part of AppEngine and bundled onto my GWT app on default, within a lib there must contain some unwanted setting. i solve my problem by remove all lib associate with AppEngine. – Ben.Yan Sep 12 '12 at 09:13

1 Answers1

1

Add datanucleus to your WEB-INF or runtime classpath.

Chris
  • 5,584
  • 9
  • 40
  • 58
  • Hi Chris, this is straightforward solution, but the reason i get rid of this lib in the first place is that this datanucleus JPA lib is a old version JPA which should be totally replace by the EclipseLink JPA i just installed. i am puzzled why the code is not using org.eclipse.persistence.jpa PersistenceProvider but the datanucleus one – Ben.Yan Sep 11 '12 at 13:23
  • moreover if i add the datanucleus lib back, is the code gonna use the old JPA associate in that lib, even the code is compile against new JPA 2.0 standard(my code contain CriteriaBuilder - intoduced in JPA2.0 )? – Ben.Yan Sep 11 '12 at 13:29