Impetus / kundera

A JPA 2.1 compliant Polyglot Object-Datastore Mapping Library for NoSQL Datastores.Please subscribe to:
http://groups.google.com/group/kundera-discuss/subscribe
Apache License 2.0
903 stars 233 forks source link

Errors Loading DSClientFactory in persistence.xml #723

Closed pluttrell closed 9 years ago

pluttrell commented 9 years ago

I'm trying to get Kundera deployed in Wildfly 8.2 and am receiving the following exception which are causing my deployment to fail and have me blocked:

2015-03-15 23:18:38,322 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 51) MSC000001: Failed to start service jboss.persistenceunit."MyTest.ear#MyTestPersistenceUnit": org.jboss.msc.service.StartException in service jboss.persistenceunit."MyTest.ear#MyTestPersistenceUnit": com.impetus.kundera.classreading.ResourceReadingException: java.io.FileNotFoundException: /content/MyTest.ear/lib/MyCore.jar (No such file or directory)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_25]
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: com.impetus.kundera.classreading.ResourceReadingException: java.io.FileNotFoundException: /content/MyTest.ear/lib/MyCore.jar (No such file or directory)
    at com.impetus.kundera.classreading.Reader.getResourceIterator(Reader.java:180) [kundera-core-2.15.1.jar:]
    at com.impetus.kundera.configure.MetamodelConfiguration.loadEntityMetadata(MetamodelConfiguration.java:226) [kundera-core-2.15.1.jar:]
    at com.impetus.kundera.configure.MetamodelConfiguration.configure(MetamodelConfiguration.java:112) [kundera-core-2.15.1.jar:]
    at com.impetus.kundera.persistence.EntityManagerFactoryImpl.configure(EntityManagerFactoryImpl.java:158) [kundera-core-2.15.1.jar:]
    at com.impetus.kundera.persistence.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:116) [kundera-core-2.15.1.jar:]
    at com.impetus.kundera.KunderaPersistence.createContainerEntityManagerFactory(KunderaPersistence.java:63) [kundera-core-2.15.1.jar:]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:318) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$1100(PersistenceUnitServiceImpl.java:67) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    ... 8 more
Caused by: java.io.FileNotFoundException: /content/MyTest.ear/lib/MyCore.jar (No such file or directory)
    at java.io.FileInputStream.open(Native Method) [rt.jar:1.8.0_25]
    at java.io.FileInputStream.<init>(FileInputStream.java:138) [rt.jar:1.8.0_25]
    at java.io.FileInputStream.<init>(FileInputStream.java:93) [rt.jar:1.8.0_25]
    at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90) [rt.jar:1.8.0_25]
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188) [rt.jar:1.8.0_25]
    at java.net.URL.openStream(URL.java:1038) [rt.jar:1.8.0_25]
    at com.impetus.kundera.classreading.Reader.getResourceIterator(Reader.java:154) [kundera-core-2.15.1.jar:]
    ... 16 more

I have searched my entire file system and I do not have a directory /content/MyTest.ear.

MyTest.ear was deploying fine prior to adding the persistence.xml.

How do I reslove this, or go about further troubleshooting it?

For reference here is my 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="MyTestPersistenceUnit">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <properties>
            <property name="kundera.nodes" value="[removed]"/>
            <property name="kundera.port" value="9042"/>
            <property name="kundera.keyspace" value="[removed]"/>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="kundera.ddl.auto.prepare" value="validate" />
            <property name="kundera.client.lookup.class" value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory" />
        </properties>
    </persistence-unit>

</persistence>

And here's my wip test code:

@PersistenceUnit
private EntityManagerFactory entityManagerFactory;

private EntityManager entityManager;

@Resource
private UserTransaction utx;

@Override
public MyTestEntity retrieveByUid(String uid) {

    if (entityManager == null){
        entityManager = entityManagerFactory.createEntityManager();
    }

    return entityManager.find(MyTestEntity.class, uid);

}

@Override
public void store(MyTestEntity myTestEntity) {

    if (entityManager == null){
        entityManager = entityManagerFactory.createEntityManager();
    }

    try {

      utx.begin();
      entityManager.persist(myTestEntity);
      utx.commit();

    } catch (Exception e) {
      try {
        utx.rollback();
      } catch (SystemException e1) {
        e1.printStackTrace();
      }
    }

}
pluttrell commented 9 years ago

Does anyone have any ideas on what might be causing this...or how to resolve it? At the moment it's blocking our PoC using Kundera.

devender-yadav commented 9 years ago

@pluttrell Sorry for late response. The team was busy with a release and hence could not respond. Can you please make sure all dependent jars are added in your class-path. content in  /content/MyTest.ear  refers to the directory where your EAR is deployed. Also, can you please share a sample project with us to help us quickly look into the issue?

HTH, Devender

karthikprasad13 commented 9 years ago

@pluttrell Please set the following property in your persistence.xml <property name="jboss.as.jpa.managed" value="false" />

Karthik.

pluttrell commented 9 years ago

@karthikprasad13

Adding <property name="jboss.as.jpa.managed" value="false" /> did work initially, however then I received NPE's because the @PersistenceUnit annotation wasn't populating the entityManagerFactory member... this was due to the fact that the class is actually created by our internal services framework which uses Google Guice for DI...and of course isn't going to properly process the @PersistenceUnit annotation. As such I removed this annotation and am instead trying to load the PersistenceUnit manually as you would outside of Wildfly, which causes the same FileNotFoundException as above.

My entity class remains the same. Here's my new wip test code:

private EntityManager entityManager;

public MyTestEntity retrieveByUid(String uid) {
    return getEntityManager().find(MyTestEntity.class, uid);
}

public void store(MyTestEntity myTestEntity) {
    getEntityManager().persist(myTestEntity);
}

private EntityManager getEntityManager(){

    if (entityManager == null){
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("MyTestPersistenceUnit");
        entityManager = entityManagerFactory.createEntityManager();
    }

   return entityManager;
}

Here's the error again (using Kundera v2.16):

java.io.FileNotFoundException: /content/MyTest.ear/lib/MyCore.jar (No such file or directory)
    at com.impetus.kundera.classreading.Reader.getResourceIterator(Reader.java:180)
    at com.impetus.kundera.configure.MetamodelConfiguration.loadEntityMetadata(MetamodelConfiguration.java:226)
    at com.impetus.kundera.configure.MetamodelConfiguration.configure(MetamodelConfiguration.java:112)
    at com.impetus.kundera.persistence.EntityManagerFactoryImpl.configure(EntityManagerFactoryImpl.java:158)
    at com.impetus.kundera.persistence.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:135)
    at com.impetus.kundera.KunderaPersistence.createEntityManagerFactory(KunderaPersistence.java:85)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
        at ....

@devender-yadav

Wildfly 8.2 does not appear to be storing the EAR file in such a location as there is no directory on my test machine /content/MyTest.ear.

chhavigangwal commented 9 years ago

@pluttrell

Please mail a sample test project at kundera@impetus.co.in to help us look into the issue further.

Chhavi

karthikprasad13 commented 9 years ago

@pluttrell

Please try including your entity classes within <class> tag and setting <exclude-unlisted-classes> to true in persistence.xml

Example:

<persistence-unit name="cassandra-test">
       <provider>com.impetus.kundera.KunderaPersistence</provider>
           <class>com.impetus.cassandra.entity.Book</class>
           <exclude-unlisted-classes>true</exclude-unlisted-classes>
           <properties> ....

Karthik.

chhavigangwal commented 9 years ago

@pluttrell

Is the issue resolved for you?

Chhavi

pluttrell commented 9 years ago

That depends... The last suggestion is an effective work around, which is why I closed this ticket.

But it's only a work around... Without looking at the code, I was quite surprised to see that Kundera was trying to read the file system in a place that doesn't exist..and further failing when it couldn't find what it was looking for. And after briefly looking at the code it appears to me that the classloading and metadata code might not work in all deployment environments, such as the one that we're deploying too...

There's another ticket 547 with a very similar issue, but the fix as proposed there (and above) did not resolve the problem for me.