-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: IllegalArgumentException: Not an entity under Glassfish4.1
PostPosted: Wed Sep 02, 2015 8:18 pm 
Newbie

Joined: Mon Jul 28, 2008 7:27 pm
Posts: 2
I was having troubles getting my personal project working under Hibernate, so I decided to start over with something I knew would work. I took the movieplex7 sample application which I could successful use under Glassfish 4.1 (https://glassfish.java.net/hol/javaee7-hol.pdf is the lab doc & the code is at http:glassfish.org/hol/movieplex7-starting-template.zip)

I changed the persistence.xml to using Hibernate as well as updating the pom.xml to pull in Hibernate 4.3.11.FINAL. Those are the only changes I made. When I make a request to the app, I get the exception:
Code:
Caused by: java.lang.IllegalArgumentException: Not an entity: class org.glassfish.movieplex7.entities.ShowTiming
   at org.hibernate.jpa.internal.metamodel.MetamodelImpl.entity(MetamodelImpl.java:203)
   at org.hibernate.jpa.criteria.QueryStructure.from(QueryStructure.java:139)
   at org.hibernate.jpa.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:173)
   at org.glassfish.movieplex7.rest.AbstractFacade.getAll(AbstractFacade.java:73)
   at org.glassfish.movieplex7.rest.ShowTimingFacadeRest.getAll(ShowTimingFacadeRest.java:101)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:497)
   at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
   at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
...


But, if I revert to using Hibernate 4.3.5.FINAL, everything works fine. (It fails with 4.3.6.FINAL - I didn't try the intermediate releases)

The persistence.xml is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
    version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="movieplex7PU" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>java:comp/DefaultDataSource</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>

        <properties>
            <!--property name="javax.persistence.schema-generation.database.action"
                      value="drop-and-create"/>
            <property name="javax.persistence.schema-generation.create-source"
                      value="script"/>
            <property name="javax.persistence.schema-generation.drop-source"
                      value="script"/>
            <property name="javax.persistence.schema-generation.create-script-source"
                      value="META-INF/create.sql"/>
            <property name="javax.persistence.schema-generation.drop-script-source"
                      value="META-INF/drop.sql"/>
            <property name="javax.persistence.sql-load-script-source"
                      value="META-INF/load.sql"/>
            <property name="eclipselink.logging.exceptions" value="false"/-->
            <!--<property name="eclipselink.logging.level" value="FINE"/>-->


            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.transaction.jta.platform"
                      value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
            <property name="hibernate.archive.autodetection" value="class, hbm, jar"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>

    </persistence-unit>

</persistence>


and the pom.xml additions were:
Code:
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.11.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>4.3.11.Final</version>
        </dependency>


If I catch the exception in the debugger, I see that the MetamodelIimpl's entities Map contains the class being queried (java.lang.Class@9692 class org.glassfish.movieplex7.entities.ShowTiming), but that the class being passed into the request is a different instance (java.lang.Class@8905 class org.glassfish.movieplex7.entities.ShowTiming). As you'd guess, they come from different class loaders (9692: WebappClassLoader (delegate=true); 8905: WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)).

I'm not sure why there are two class loaders though I'm assuming its something to do with two different class scans during application initialization. Thus, I'm wondering if there's something I've done wrong in the application deployment - though as I said, the persistence.xml and pom.xml files were the only ones I changed. And, the original code (using EclipseLink) as well as Hibernate 4.3.5.FINAL work just fine.

While I've worked with Hibernate for years, this is my first time using it under JavaEE without and "Spring-isms" :). I'd appreciate any advice.

Thanks,
Ken


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.