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

com.impetus.kundera.KunderaException: Entitymatadata should not be null #305

Closed TheGeekPharaoh closed 11 years ago

TheGeekPharaoh commented 11 years ago

I'm playing around with Kundera for the first time, using 2.6-SNAPSHOT on Cassandra. My entity class looks like this:

@Entity(name = "User") @Table(name = "users", schema = "dev@KunderaTests") public class User implements Serializable {

private static final long serialVersionUID = -6949475495725775621L;

@Column(name = "user_name")
private String name = null;

@Column(name = "user_age")
private int age = 0;

@Id
private String id = null;

...getters & setters....

}

...and my persistence.xml looks like this...

<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="KunderaTests">
    <provider>com.impetus.kundera.KunderaPersistence</provider>
    <properties>
        <property name="kundera.nodes" value="localhost" />
        <property name="kundera.port" value="9160" />
        <property name="kundera.keyspace" value="dev" />
        <property name="kundera.dialect" value="cassandra" />
        <property name="kundera.client.lookup.class"
            value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
        <property name="jboss.entity.manager.factory.jndi.name"
            value="java:/KunderaTestsEntityManagerFactory" />
        <!-- <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider" 
            /> <property name="kundera.cache.config.resource" value="/ehcache-test.xml" 
            /> -->
    </properties>
</persistence-unit>

My project starts up just fine, with no errors or exceptions. However, when I run this code:

    EntityManagerFactory emf = Persistence
            .createEntityManagerFactory("KunderaTests");
    EntityManager em = emf.createEntityManager();

    User u = new User();
    u.setAge(30);
    u.setName("Test");
    u.setId(String.valueOf(System.currentTimeMillis()));

    em.persist(u);
    em.close();
    emf.close();

I get an Exception saying, "com.impetus.kundera.KunderaException: Entitymatadata should not be null" and I see the following line written to my logs:

"No Entity metadata found for the class class com.test.User. Any CRUD operation on this entity will fail.If your entity is for RDBMS, make sure you put fully qualified entity class name under tag in persistence.xml for RDBMS persistence unit. Returning null value."

I looked at the "Getting Started" guide and everything seems to be in order according to the examples. Any idea why I'm getting this?

mevivs commented 11 years ago

Looks like, entities are not loaded. One question, please verify if your persistence.xml is with in (say root/META-INF folder and your entity classes should be available within root folder.

If they are packaged within a jar, then please add jar path within tag in persistence.xml

-Vivek

TheGeekPharaoh commented 11 years ago

The persistence.xml file is in the appropriate place. The entity classes are in the same JAR as the persistence.xml. Do I still need to add the jar path to the persistence.xml file?

mevivs commented 11 years ago

Nope. Can you please share packaging of your jar file?

-Vivek

mevivs commented 11 years ago

Alternatively, possible for you to bundle classes and persistence.xml within war(under WEB-INF folder), classes with classes folder and META-INF/persistence.xml with WEB-INF folder?

-Vivek

TheGeekPharaoh commented 11 years ago

My EAR structure looks like this:

KunderaTests.ear ->KunderaTestsWeb.war ->KunderaTests-ejb.jar (this is where my persistence.xml and Entity classes are)

The KunderaTests-ejb.jar is pretty simple. One package with a couple of @Entity classes. The META-INF directory has the persistence.xml file.

For the record, I'm using JBoss EAP 6.1 and Kundera-trunk for my testing, with Cassandra as the datastore.

TheGeekPharaoh commented 11 years ago

Any update on this?

pires commented 11 years ago

I follow the same structure in a project of mine that is working with latest trunk. Please take a look at https://github.com/pires/sherlock.

mevivs commented 11 years ago

Hi,

Can you give it a try with:

  1. jboss.as.jpa.managed as false in persistence.xml
  2. include your entity classes with in tag and to true in persistence.xml

-Vivek

TheGeekPharaoh commented 11 years ago

Vivek --

I understand point #1, but I'm afraid I don't understand what you're asking me to try in point #2. Can you restate?

pires commented 11 years ago

@sdnakhla I think he meant for you to include all your entity classes in <class></class>tag in persistence.xml.

TheGeekPharaoh commented 11 years ago

I have made the recommended changes. When ONLY setting "jboss.as.jpa.managed" to "false", the error persists. When also adding the entries with my entity classes declare, I get the following exception:

Caused by javax.el.ELException with message: "java.lang.ClassCastException: org.jboss.modules.ModuleClassLoader cannot be cast to java.net.URLClassLoader"

For further reference, here is my persistence.xml file:

<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="KunderaTests">
    <provider>com.impetus.kundera.KunderaPersistence</provider>
    <class>com.test.Company</class>
    <class>com.test.User</class>
    <properties>
        <property name="jboss.as.jpa.managed" value="false" />
        <property name="kundera.nodes" value="localhost" />
        <property name="kundera.port" value="9160" />
        <property name="kundera.keyspace" value="dev" />
        <property name="kundera.dialect" value="cassandra" />
        <property name="kundera.client.lookup.class"
            value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
        <property name="jboss.entity.manager.factory.jndi.name"
            value="java:/KunderaTestsEntityManagerFactory" />
    </properties>
</persistence-unit>

mevivs commented 11 years ago

Did you take an update of latest trunk?

-Vivek

TheGeekPharaoh commented 11 years ago

Yes, all tests were conducted with code from the trunk that was downloaded and compiled yesterday evening.

mevivs commented 11 years ago

KK, Can you please look into this and share Jboss sample apps persistence.xml and other configurations?

-Vivek

TheGeekPharaoh commented 11 years ago

I thought this may be related to the fact that I was using JBoss Seam as my application framework, so I created a new JavaEE6 project using only standard libraries. I re-ran the tests, but received the same error as before. Is there any update to this issue?

TheGeekPharaoh commented 11 years ago

CORRECTION...

Looks like this has been resolved in 2.6-FINAL. Thanks!

vinitsharma87 commented 8 years ago

Hi, can anyone just explain a little like, where do we have to place the jar file consisting of the entity classes and if we don't place the jar file like this, then only adding the class tag in persistence.xml would be sufficient or not ? Kindly help!

chhavigangwal commented 8 years ago

It should be in the classpath of your project else , when placed externally you need to add it's path in persistence.xml by using

<jar-file>/home/impetus/perf_n.jar</jar-file> <jar-file>/home/impetus/perf.jar</jar-file>

Chhavi