No Entity metadata found for the class

本小妞迷上赌 提交于 2019-12-08 05:49:01

问题


I'm back with the same problem ...

I'm trying to uses queries in my Cassandra DB with Kundera (Cassandra ORM), this queries work in an others project but when I try to do it in webapp (using tomcat 6.0), I got this error :

com.impetus.kundera.metadata.KunderaMetadataManager  - No Entity metadata found for the class

=> JavaNullPointerException.

But when I leave the persistence.xml from my project I got an other error. (NoPersistence.xml found or something ... )

So, my project found Persistence.xml, but not my Entity class : fileCassandra.

You can see my persistence.xml :

   <?xml version="1.0" encoding="UTF-8"?>
<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">
    <!--  192.168.3.107 -->
    <persistence-unit name="cassandra_pu">
        <provider>com.impetus.kundera.KunderaPersistence</provider>     
        <class>net.***.common.db.***.FileCassandra</class>

        <properties>            
            <property name="kundera.nodes" value="localhost"/>
            <property name="kundera.port" value="9160"/>
            <property name="kundera.keyspace" value="KunderaExamples"/>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
            <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>
</persistence>  

net..common.db..FileCassandra I must replace by * because it's name from my companie ;)

The same methods (include EntityManager) works in junit on other project, when I build my project in Tomcat, this error appears ...


回答1:


Only issue which i can see is classes and persistence.xml location.

try to place persistence.xml within /WEB-INF/classes/META-INF/, Provided that your entity definitions are within classes folder!

-Vivek




回答2:


This happens when you have multiple entries of the same class in your classpath.

The ideal place to have your entities is closest to the same class loader which loads kundera core and client(HBase, Cassandra etc.).

For example, if these kundera files are under WEB-INF/lib, you'd rather have your entities under the application where as if kundera files are on the applications lib folder, better bundle your entities in a jar and put them there (and remove the entities in your app).



来源:https://stackoverflow.com/questions/11087167/no-entity-metadata-found-for-the-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!