Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPA Metadata not loading for User Class #131

Closed
phillipCouto opened this issue Oct 11, 2012 · 29 comments
Closed

JPA Metadata not loading for User Class #131

phillipCouto opened this issue Oct 11, 2012 · 29 comments
Milestone

Comments

@phillipCouto
Copy link

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.

@phillipCouto
Copy link
Author

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

@xamry
Copy link
Contributor

xamry commented Oct 11, 2012

You entity class definition is correct. Kundera is not able to find your
entity class into classpath and hence is not able to create metadata for
it, which is crucial.

If you could send me your entire code, I would be able to have a look at it.

Regards,
Amresh

On Thu, Oct 11, 2012 at 10:34 AM, Phillip Couto [email protected]:

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


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-9328732.

@phillipCouto
Copy link
Author

I zipped the project. https://s3.amazonaws.com/stembackup/Cassandra+Test.zip

@xamry
Copy link
Contributor

xamry commented Oct 11, 2012

Please remove tag from persistence.xml and replace property
name kundera_ddl_auto_prepare with
kundera.ddl.auto.prepare and try again.

Regards,
Amresh

On Thu, Oct 11, 2012 at 11:06 AM, Phillip Couto [email protected]:

I zipped the project.
https://s3.amazonaws.com/stembackup/Cassandra+Test.zip


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-9329118.

@phillipCouto
Copy link
Author

No luck same error

@xamry
Copy link
Contributor

xamry commented Oct 11, 2012

I ran your code inside enclipe and it works for me perfectly . Are you
running your program in some IDE (which one?), or from command line?

In the past, some users have reported exactly similar issues while using
Netbeans. Sometimes clearing cache resolves problem.

Amresh

On Thu, Oct 11, 2012 at 11:26 AM, Phillip Couto [email protected]:

No luck same error


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-9329388.

@phillipCouto
Copy link
Author

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

@phillipCouto
Copy link
Author

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.

@mevivs
Copy link
Collaborator

mevivs commented Oct 11, 2012

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

@phillipCouto
Copy link
Author

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

@phillipCouto
Copy link
Author

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

@mevivs
Copy link
Collaborator

mevivs commented Oct 11, 2012

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

-Vivek

@phillipCouto
Copy link
Author

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

@phillipCouto
Copy link
Author

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.

@xamry
Copy link
Contributor

xamry commented Oct 11, 2012

Let us know when you manage to get this working on Windows. We are
collating commonly encountered issues by users and this could be a valuable
addition.

Regards,
Amresh

On Thu, Oct 11, 2012 at 4:43 PM, Phillip Couto [email protected]:

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.


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-9336319.

@phillipCouto phillipCouto reopened this Oct 16, 2012
@phillipCouto
Copy link
Author

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.

@mevivs
Copy link
Collaborator

mevivs commented Oct 16, 2012

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

-Vivek

@jeremyhahn
Copy link

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.

@mevivs
Copy link
Collaborator

mevivs commented Nov 7, 2012

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.

@jeremyhahn
Copy link

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.

@mevivs
Copy link
Collaborator

mevivs commented Nov 8, 2012

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

@jeremyhahn
Copy link

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.

@mevivs
Copy link
Collaborator

mevivs commented Nov 8, 2012

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

@mevivs
Copy link
Collaborator

mevivs commented Jan 24, 2013

Looks like not an issue anymore. closing this with 2.3

-Vive

@mevivs mevivs closed this as completed Jan 24, 2013
@pabloetoledo
Copy link

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.

@mevivs
Copy link
Collaborator

mevivs commented Aug 21, 2013

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

-Vivek

@vinitsharma87
Copy link

Hello @mevivs, @xamry, I need your help. I am facing this similar kind of error. Can you please provide me your email, so that I can connect with you as early as possible ? I am also facing this similar problem with Play! 2.4 and cassandra integration. Need your help.

@achaiah
Copy link

achaiah commented Apr 15, 2016

Same here with Play 2.4. Anyone know what the deal is?

@si24803
Copy link

si24803 commented Sep 22, 2017

@achaiah Do you mean Play in dev or prod (packaged)? In dev mode (sbt run on the project dir) I have to compile my entities classes by myself. Play doesn't pick them up if they are in packages different from the ones it creates on setup of the project. I believe there's a way to include other packages but haven't figured that part out yet. I'm using Play 2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants