Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326552

Summary: redeployment does not work on weblogic for non-managed persistence units, "not a known entity type"
Product: z_Archived Reporter: James Sutherland <jamesssss>
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: NEW --- QA Contact:
Severity: major    
Priority: P2 CC: a.elmaksoud, iker.olabarria, john.cecere, michael.f.obrien, tom.ware, tszho.siu
Version: unspecifiedFlags: michael.f.obrien: documentation+
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#Results_Matrix
Whiteboard:
Bug Depends on:    
Bug Blocks: 338676    

Description James Sutherland CLA 2010-09-29 11:28:32 EDT
The error,

java.lang.IllegalArgumentException: Object: <object> is not a known entity type.

is thrown when you redeploye a non-managed persistence unit on weblogic.  The error most likely occurs on other servers.

The error occurs because the ServerSession is cached in the EntityManagerSetupImpl static, so on createEntityManagerFactory() the old one is used with the old descriptors/class before the redeployment.

If close() is called by the application before the undeploy, it should in theory resolve the issue, but the application generally will not be able to do this.  We also have a finalize method, but this does not seem to work.

If we cannot fix the issue we should at least (and probably even if we fix it)
- improve the error message "java.lang.IllegalArgumentException: Object: <object>, of class <class> is not a known entity type. If a redeployment has occurred the session may have the wrong class loader, and need to be cleared."
- add a clear method to our PersistenceProvider, or a destroy method to EntityManagerFactory.

I have also seen issues that weaving does not occur for non-managed persistence units.

We need to have tests that run in all of our application servers that use a non-managed persistence unit and verify weaving and redeployment and general usage.
Comment 1 James Sutherland CLA 2011-03-02 09:09:50 EST
There should also be a way to manually undeploy a persistence unit.  Their is an undeploy on EntityManagerSetupImpl, but no way to access this from an EntityManagerFactoryImpl.  It should have a getEntityManagerSetup method, as well as an undeploy method.

Also the cached setup impls in the static EntityManagerSetupImpl never seem to ever get cleared, this does not seem correct.
Comment 2 Ahmed Abb Elmaksoud CLA 2013-03-12 13:04:46 EDT
i have same issue any news to solve it >>>>>work around restart the server
Comment 3 John Cecere CLA 2014-09-24 09:32:29 EDT
Just moved from JPA 1/Eclipse 2.1 to JPA 2/Eclipse 2.3 and started encountering this problem. Having to bounce WebLogic every time I do a redeploy is becoming time-consuming. Is this fixed in a later release? Are there any plans to fix it in 2.3?
Comment 4 John Cecere CLA 2014-09-25 10:23:13 EDT
I tried implementing a listener in WebLogic with a preStop method that closes the EntityManagerFactory. This had no effect.
Comment 5 Ziho Siu CLA 2014-11-30 22:34:20 EST
Encounter the same issue, definitely there is a caching of old class definition issue.

The classloader of eclipselink library is the WebLogic system class loader whereas the classloader of the entity classes is the EAR application class loader, everytime when redeployment of application occur, a new set of entity classes are loaded in a new EAR application class loader.

Somehow the eclipselink's EntityManagerFactory in the WebLogic system class loader still reference to the old entity classes definition.

So, everytime need to restart the server when re-deployment is needed.
Comment 6 Ahmed Abb Elmaksoud CLA 2014-12-01 03:30:51 EST
This issue happen when u create EntityManagerFactory manulally like Persistence.createEntityManagerFactory serveral times.
Your application should create it once on startup and destory it when the application undeploy
If its web app create ServletContextListener

*in contextInitialized method create it once[as golobal varibale or using single tone class] EntityManagerFactory fact = Persistence.createEntityManagerFactory


*and in contextDestroyed method fact.close()
Comment 7 Ziho Siu CLA 2014-12-01 03:35:02 EST
(In reply to Ahmed Abb Elmaksoud from comment #6)
> This issue happen when u create EntityManagerFactory manulally like
> Persistence.createEntityManagerFactory serveral times.
> Your application should create it once on startup and destory it when the
> application undeploy
> If its web app create ServletContextListener
> 
> *in contextInitialized method create it once[as golobal varibale or using
> single tone class] EntityManagerFactory fact =
> Persistence.createEntityManagerFactory
> 
> 
> *and in contextDestroyed method fact.close()

In my case, no, it is managed by the server, I called it through injection annotation @PersistenceContext. I am not sure how to close the container-managed EntityManagerFactory.
Comment 8 Ahmed Abb Elmaksoud CLA 2014-12-01 03:41:33 EST
Try to search in your app anyone else is using EntityManagerFactory or not may be any other Lib
Comment 9 Azuimuts iker CLA 2015-02-23 09:13:00 EST
I think there is no bug.  I had the same behaviour because of not closing the persistence service. 

Into my infraestrcuture i use  weblogic + eclipselink + guice-persist. 

Guice has a PersisteService. In many example u can see how to start this service... but not to stop it.  If you don't stop it the behaviour is that after a redploy Weblogic does not know about the entities, getting an ", "not a known entity type" error. 

... but if you stop the PersistService,  there is no issue.!!! 

I started also an Stackoverflow post about this: 

http://stackoverflow.com/questions/28604296/eclipselink-jpa-guice-persist-and-redeployments
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:07:21 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink