-->
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.  [ 9 posts ] 
Author Message
 Post subject: "Not an entity" error when entities are in external jar
PostPosted: Wed Dec 22, 2010 6:33 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Hi guys
Our plan was to have a project setup like this:
frontend.war - includes common.jar. Frontend using entities as DTO's.
common.jar - our entities, but no persistence.xml
backend.war - includes common.jar and has persistence.xml. Contains business logic and persistence.

But this doesn't seem to work, we get "Not an entity: no.evote..." exceptions on all invocations. This is the stack trace:

javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5194)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5092)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4880)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:213)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at $Proxy518.findById(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:144)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:174)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1486)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:990)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:742)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:496)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:537)
Caused by: java.lang.IllegalArgumentException: Not an entity: class no.evote.model.Locale
at org.hibernate.ejb.metamodel.MetamodelImpl.entity(MetamodelImpl.java:160)
at org.hibernate.ejb.criteria.QueryStructure.from(QueryStructure.java:138)
at org.hibernate.ejb.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:179)
at no.evote.service.impl.BaseServiceImpl.findEntityById(BaseServiceImpl.java:127)
at no.evote.service.impl.LocaleServiceImpl.findById(LocaleServiceImpl.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5367)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at no.evote.service.util.ErrorInterceptor.cleanException(ErrorInterceptor.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at no.evote.service.security.SecurityInterceptor.name(SecurityInterceptor.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at no.evote.service.util.LoggingInterceptor.logCall(LoggingInterceptor.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.GeneratedMethodAccessor153.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:371)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5339)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5327)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:206)
... 19 more
|#]

We get this both on Glassfish 3.0.1 and Glassfish 3.1 (M7).

My question: Is this setup supposed to work?

Right now we have duplicated all entities so that they are both in common.jar and backend.war, this is working but it's not optimal.

And a very strange side note: I tried this setup in unit tests that use Glassfish Embedded (3.0.1). It was actually working in about 1 out of 10 times I tried. I spent an hour just rerunning tests, and I did not change anything between tests. Either all tests passed or all tests failed.

Regards,

Anders


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Wed Dec 22, 2010 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
no that's very dangerous, you should never have duplicate classes in the same application.
Hibernate (and any other framework) needs to identify your entities via the class type, if you have two on classpath, it's unpredictable which one is loaded first, in which classloader, and as you noticed in the unit tests, it might even appear to work - sometimes - but just never do it!
Make an ear, and have your common.jar included only once in it, then both frontend and backend are able to reference the same entities.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Wed Jan 05, 2011 11:21 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Hi, and thanks for helping.

Yes having duplicate classes is very bad, that's why I want to avoid it. But it is working so until we find another way to do it we have to keep them duplicated.

I would like to keep our webapps as plain and simple .war's, moving to .ear must be the final option. I thought our approach would work fine with war's.

But to clarify, the case where my unit tests worked in 1 out of 10 runs.. This was when I deleted the entity classes from the webapp, and only having them inn common.jar.

Regards,
Anders


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Wed Jan 05, 2011 12:51 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
But it is working so until we find another way to do it we have to keep them duplicated.

I'm sorry to have to answer that way, but really it won't work, there's no workaround possible. You have to guarantee class uniqueness, or completely isolate the wars. This is not just an Hibernate requirement, you will have all sort of issues.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Fri Jan 07, 2011 4:31 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Hi again.

I think you misunderstood.. Forget about the duplicated classes, that is just a workaround.

What I am trying to find out is whether this project structure is supposed to work:

common.jar - JPA2 entities, but no persistence.xml
frontend.war - has common.jar in WEB-INF/lib. No persistence.xml, should just use entities as DTO's
backend.war - has common.jar in WEB-INF/lib and has persistence.xml. Should discover all entities in common.jar as JPA2 entities.

Should this work?

-Anders


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Thu Feb 03, 2011 9:33 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Would really like some input on this..

-Anders


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Mon Feb 07, 2011 2:21 am 
Newbie

Joined: Mon Feb 07, 2011 2:04 am
Posts: 1
Hi,
i have a similar problem as the one mentioned here.
my packaging structure:
+projectName
+META-INF
+context.xml
+persistence.xml
+MANIFEST.MF
+resources
+css
+image
+WEB-INF
+classes
+org.some.internal.entities
+org.some.other.beans
+import.sql
+lib
+org.a.jar.file.containing.many.shared.entities.no.persistence.xml
+seam.*.jar
+postgres.jar
+beans.xml
+faces-config.xml
+web.xml

There is nothing declared in beans.xml, web.xml and faces-config.

persistence.xml content:
Code:
   <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="hibernate.default_schema" value="schema"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/cm.telpayEntityManagerFactory"/>
      </properties> 


When launching the application,
Code:
i have the following error:   ... 54 more
Caused by: java.lang.IllegalArgumentException: Not an entity: class cm.telpay.server.model.Member
   at org.hibernate.ejb.metamodel.MetamodelImpl.entity(MetamodelImpl.java:160) [:3.6.0.Final]
   at org.hibernate.ejb.criteria.QueryStructure.from(QueryStructure.java:138) [:3.6.0.Final]
   at org.hibernate.ejb.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:179) [:3.6.0.Final]
   at cm.telpay.server.data.MemberListProducer.retrieveAllMembersOrderedByName(MemberListProducer.java:45) [:]
   ... 64 more


please can somebody give me a hint?
Thank you a lot in advance


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Sat Feb 19, 2011 7:57 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
What application server are you using? What version of Hibernate? Looks like exactly the same problem that I have.

I'm beginning to think this approach just isn't possible, but I really don't understand why not.


Top
 Profile  
 
 Post subject: Re: "Not an entity" error when entities are in external jar
PostPosted: Mon Feb 21, 2011 11:21 am 
Newbie

Joined: Fri Mar 12, 2010 9:42 am
Posts: 19
Finally found out how to do this.. Got some help over at stackoverflow:
http://stackoverflow.com/questions/5064 ... wo-webapps

Seems there are two ways to solve it:
1) Specify the entity jar file in persistence.xml: <jar-file>common.jar</jar-file>

2) List all entities by class name in persistence.xml using <class>com.mycompany.model.Locale</class>

We ended up using the second approach. I couldn't get the first approach working when deploying with eclipse, and it would also require us to update the persistence.xml each time version numbers change (since we build with maven). Any solutions to these problems?

Anyway, so happy we finally figured this one out.

-Anders


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

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.