Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

JPA Metadata not loading for User Class #131

Closed
phillipCouto opened this Issue · 26 comments

5 participants

Phillip Couto Amresh Vivek Mishra Jeremy Hahn pabloetoledo
Phillip Couto

I ran through the getting started in 5 minutes guide and I am running into this error consistently.

Oct 11, 2012 12:53:41 AM com.impetus.kundera.persistence.PersistenceValidator isValidEntityObject SEVERE: class com.stemstudios.test.Domain.User is not a JPA managed object as we couldn't find metadata for it. This object can't be persisted

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="cassandra_pu">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <class>com.stemstudios.test.Domain.User</class>
        <properties>            
            <property name="kundera.nodes" value="192.168.0.101"/>
            <property name="kundera.port" value="9160"/>
            <property name="kundera.keyspace" value="DEMO"/>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="kundera_ddl_auto_prepare" value="update"/>
            <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>

I know the xml document is being parsed correctly based on this console output:

Oct 11, 2012 12:53:41 AM com.impetus.kundera.persistence.EntityManagerFactoryImpl INFO: EntityManagerFactory created for persistence unit : cassandra_pu

Not sure if this is a bug or user error on my part.

Phillip Couto

BTW here is my User class I am trying to persist:

package com.stemstudios.test.Domain;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "User", schema = "DEMO@cassandra_pu")
public class User 
{
    @Id
    private String userId;

    @Column(name="first_name")
    private String firstName;

    @Column(name="last_name")
    private String lastName;

    @Column(name="city")
    private String city;    

    public User()
    {
    }

    public String getUserId()
    {
        return userId;
    }
    public void setUserId(String userId)
    {
        this.userId = userId;
    }
    public String getFirstName()
    {
        return firstName;
    }
    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }
    public String getLastName()
    {
        return lastName;
    }
    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }
    public String getCity()
    {
        return city;
    }
    public void setCity(String city)
    {
        this.city = city;
    } 
}
Amresh
Amresh
Phillip Couto

No luck same error

Amresh
Phillip Couto

I am running my code in Eclipse Indigo. Maybe my configuration is wonky. I will try using the latest one.

Phillip Couto

Downloaded new eclipse. Made new workspace. Created new maven project and added kundera-cassandra. Recreated the files right from the walk through and still same error.

Vivek Mishra
Collaborator

Please share complete server log.

Have a look at sample project i have uploaded at:
https://github.com/downloads/impetus-opensource/Kundera-Examples/CassandraIssues_neil.tar.gz

If this works for you. Also have a look at:
https://github.com/impetus-opensource/Kundera/wiki/Troubleshooting ( Point 2)

-Vivek

Phillip Couto

I ran it and this is console output I get:

2012-10-11 03:07:12,948 [INFO ] [main] com.impetus.kundera.configure.SchemaConfiguration - Configuring schema export for: cassandratest
2012-10-11 03:07:13,099 [INFO ] [main] com.impetus.kundera.persistence.EntityManagerFactoryImpl - EntityManagerFactory created for persistence unit : cassandratest
2012-10-11 03:07:13,119 [INFO ] [main] com.impetus.kundera.client.ClientResolver - Returning client instance for:cassandratest
2012-10-11 03:07:13,134 [WARN ] [main] com.impetus.kundera.metadata.KunderaMetadataManager - No Entity metadata found for the class class com.sample.entities.Car. 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.
2012-10-11 03:07:13,134 [ERROR] [main] com.impetus.kundera.persistence.PersistenceValidator - class com.sample.entities.Car is not a JPA managed object as we couldn't find metadata for it. This object can't be persisted
Exception in thread "main" com.impetus.kundera.KunderaException: java.lang.IllegalArgumentException: Entity object is invalid, operation failed. Please check previous log message for details
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:208)
at com.sample.entities.Runner.main(Runner.java:38)
Caused by: java.lang.IllegalArgumentException: Entity object is invalid, operation failed. Please check previous log message for details
at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:143)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:202)
... 1 more

Phillip Couto

BTW not sure if this is of concern I am using JDK 1.7

Vivek Mishra
Collaborator

Might be. i did not try it yet on jdk 1.7, using cassandra 1.1.5?

-Vivek

Phillip Couto

Yeap. I installed JDK 6u35 and still nothing. It feels like its some settings for my eclispe and I am running this in windows.

Phillip Couto

Ok so I just validated that it has to do with it running in windows. I am closing the issue as it is a configuration thing on my part that I will have to resolve. Thanks for your help and time.

Amresh
Phillip Couto phillipCouto reopened this
Phillip Couto

The issue is with the Reader class under the com.impetus.kundera.classreading package.

This line of code is taking the class directory and trying to read it as a Jar file:

            else if (!urlString.endsWith("/"))
            {
                return new JarFileIterator(url.openStream(), filter);
            }

This can be found on lines 150 to 153. Looks like Eclipse in windows does not add a slash at the end of the classpath and therefore the Reader feels like it is a file. I suggest this be changed to check if the provided classpath URL is a file or directory before further processing. If it is a file then you can work through if it is a JAR file or .class file.

Vivek Mishra
Collaborator

Could you please submit your pull request(With code changes which is working for you)?

-Vivek

Jeremy Hahn

Has there been any progress on this? I'm seeing the same issue when bundling my entities/daos in a commons jar and then attempting to persist from another application.

Vivek Mishra
Collaborator

This is the issue related to windows env.

If you are bundling your entities within a jar file, try to add that jar under "" tag. Else those should be available within classpath.

Have a look at:
#90

for more details.

Jeremy Hahn

What do you mean try adding that jar under "" tag? I presume a property tag in persistence.xml?

Here is my persistence.xml file, which does not work:

https://gist.github.com/4039678

I also tried using instead of "" which does not work either.

Vivek Mishra
Collaborator

Hi,
Please add your jar file under <jar></jar> tag, it should work for you.

try like:

<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_1_0.xsd" version="2.0">
<persistence-unit name="default">
    <provider>com.impetus.kundera.KunderaPersistence</provider>
    <properties>
        <property name="kundera.nodes" value="localhost" />
        <property name="kundera.port" value="27017" />
        <property name="kundera.keyspace" value="testdb" />
        <property name="kundera.dialect" value="mongodb" />
        <property name="kundera.client.lookup.class" value="com.impetus.client.mongodb.MongoDBClientFactory" />
        <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
        <property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
        <property name="" value="my-commons.jar"/>
    </properties>
   <jar-file>my-commons.jar</jar-file>
  <exclude-unlisted-classes>true</exclude-unlisted-classes>
 </persistence-unit>
</persistence>

please mention absolute path of my-commons.jar

-Vivek

Jeremy Hahn

ok that worked, thank you very much!

i am, however, getting this error even though my test is now passing. Am I missing a schema reference/version or something?

13:06:10,921 ERROR com.impetus.kundera.loader.PersistenceXMLLoader$ErrorLogger PersistenceXMLLoader:431 - Error parsing XML: XML InputStream(-1) cvc-complex-type.2.4.d: Invalid content was found starting with element 'jar-file'. No child element is expected at this point.

Vivek Mishra
Collaborator

looks like 2.0 schema is not available with your persistence.xml

can see that you referring to:

"http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" in place of 2.0

Vivek Mishra
Collaborator

Looks like not an issue anymore. closing this with 2.3

-Vive

Vivek Mishra mevivs closed this
pabloetoledo

I have the same problem!

"
class entities.Person is not a JPA managed object as we couldn't find metadata for it. This object can't be persisted
"

I'm using NetBeans 7.2.

Vivek Mishra
Collaborator

This looks to me as a packaging issue. Either Person entity is not on the classpath or persistence.xml is not mapped correctly.

-Vivek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.