Unknown bean object class after hot deployment: netbeans 6.9 + glassfish 2.1 + eclipselink jpa 2.0

When I deploy my application, it works fine until I make a change, save, and insecurely deploy the application. At the moment, I get an unknown entity bean class error in a class that has @entity and is included in my persistence.xml. When this happens, everything that works with jpa stops working. Only if I restart the server will my jpa files start working again.

If I go back to deployment while saving in my project, and I only manually save and deploy, I get the same results.

Is this just a netbeans / glassfish bug? Or is there something wrong with my jpa setup?

An exception

java.lang.IllegalArgumentException: Unknown entity bean class: class amc.nase.idms.persistence.model.SecSession, please verify that this class has been marked with the @Entity annotation. at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:592) at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:476) at amc.nase.idms.persistence.controllers.SecSessionJpaController.findSecSession(SecSessionJpaController.java:134) at amc.nase.idms.services.SecurityServiceHelper.validateSession(SecurityServiceHelper.java:106) at amc.nase.idms.services.SecurityService.validateSession(SecurityService.java:78) at amc.nase.idms.web.extensions.SecurityInterceptor.intercept(SecurityInterceptor.java:64) at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155) at net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113) 

Essence

 import java.io.Serializable; import java.util.Date; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @Entity @Table(name = "SEC_SESSION",schema = "APPLOCK") @NamedQueries({ @NamedQuery(name = "SecSession.findAll", query = "SELECT s FROM SecSession s"), @NamedQuery(name = "SecSession.findBySessionid", query = "SELECT s FROM SecSession s WHERE s.sessionid = :sessionid"), @NamedQuery(name = "SecSession.findByOrgid", query = "SELECT s FROM SecSession s WHERE s.orgid = :orgid"), @NamedQuery(name = "SecSession.findByConnecttime", query = "SELECT s FROM SecSession s WHERE s.connecttime = :connecttime"), @NamedQuery(name = "SecSession.findByConnectip", query = "SELECT s FROM SecSession s WHERE s.connectip = :connectip")}) public class SecSession implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "SESSIONID") private String sessionid; @Basic(optional = false) @Column(name = "ORGID") private Integer orgid; @Basic(optional = false) @Column(name = "CONNECTTIME") @Temporal(TemporalType.TIMESTAMP) private Date connecttime; @Basic(optional = false) @Column(name = "CONNECTIP") private String connectip; public SecSession() { } public SecSession(String sessionid) { this.sessionid = sessionid; } public SecSession(String sessionid, Integer orgid, Date connecttime, String connectip) { this.sessionid = sessionid; this.orgid = orgid; this.connecttime = connecttime; this.connectip = connectip; } public String getSessionid() { return sessionid; } public void setSessionid(String sessionid) { this.sessionid = sessionid; } public Integer getOrgid() { return orgid; } public void setOrgid(Integer orgid) { this.orgid = orgid; } public Date getConnecttime() { return connecttime; } public void setConnecttime(Date connecttime) { this.connecttime = connecttime; } public String getConnectip() { return connectip; } public void setConnectip(String connectip) { this.connectip = connectip; } @Override public int hashCode() { int hash = 0; hash += (sessionid != null ? sessionid.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { if (!(object instanceof SecSession)) { return false; } SecSession other = (SecSession) object; if ((this.sessionid == null && other.sessionid != null) || (this.sessionid != null && !this.sessionid.equals(other.sessionid))) { return false; } return true; } @Override public String toString() { return "gov.faa.nase.security.persistence.SecSession[sessionid=" + sessionid + "]"; } public SecSessionTO transfer(){ SecSessionTO to = new SecSessionTO(); to.setConnectIP(connectip); to.setConnectTime(connecttime); to.setOrgId(orgid); to.setSessionId(sessionid); return to; } } 

Xml persistence

 <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" 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"> <persistence-unit name="iDMSPU" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>jdbc/dms</jta-data-source> <class>amc.nase.idms.persistence.model.Org</class> <class>amc.nase.idms.persistence.model.SecApp</class> <class>amc.nase.idms.persistence.model.SecPermission</class> <class>amc.nase.idms.persistence.model.SecRole</class> <class>amc.nase.idms.persistence.model.SecSession</class> <class>amc.nase.idms.persistence.model.SecUserRole</class> <class>amc.nase.idms.persistence.model.TurAccessCodes</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties/> </persistence-unit> </persistence> 

UPDATE

Web XML

 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>IOCInjector.PACKAGE</param-name> <param-value>amc.nase.idms.services</param-value> </context-param> <listener> <listener-class>amc.nase.idms.web.IOCInitializer</listener-class> </listener> <filter> <display-name>Stripes Filter</display-name> <filter-name>StripesFilter</filter-name> <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> <init-param> <param-name>ActionResolver.Packages</param-name> <param-value>amc.nase.idms.web.actions</param-value> </init-param> <init-param> <param-name>Extension.Packages</param-name> <param-value>amc.nase.idms.web.extensions</param-value> </init-param> <init-param> <param-name>Configuration.Class</param-name> <param-value>amc.nase.idms.web.extensions.IOCRuntimeConfiguration</param-value> </init-param> <init-param> <param-name>ActionBeanContextFactory.Class</param-name> <param-value>amc.nase.idms.web.extensions.IDMSActionBeanContextFactory</param-value> </init-param> <init-param> <param-name>ActionResolver.Class</param-name> <param-value>amc.nase.idms.web.extensions.IDMSActionResolver</param-value> </init-param> </filter> <filter> <description>Dynamically maps URLs to ActionBeans.</description> <display-name>Stripes Dynamic Mapping Filter</display-name> <filter-name>DynamicMappingFilter</filter-name> <filter-class>net.sourceforge.stripes.controller.DynamicMappingFilter</filter-class> </filter> <filter-mapping> <filter-name>StripesFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping> <filter-mapping> <filter-name>DynamicMappingFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <resource-ref> <res-ref-name>jdbc/dms</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <resource-ref> <res-ref-name>jdbc/harv</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </web-app> 
+3
java java-ee jpa eclipselink
source share
5 answers

The problem is that the old save block with references to the old classes remains after your redeployment. Make sure the old EntityManagerFactory is closed. Glassfish should handle this for any managed factories, such as SessionBean, but if you manage your factories, you need to ensure they are closed.

+2
source share

Your problem is quite interesting. So, I just keep reading about it more. I found a thread in SO itself that still has no JPA solution - an unknown object bean class . Not only in SO, but also in some external forums:

After a while, I found another thread in SO itself, " Java Persistance Problem "

Question and Answer James :

Since the above comments suggest this seems to be the problem with the eclipse plug in for glass fish. I have no problem deploying the ear manually.

Thank you all for your help.

James

Finally it sounds like a problem :) http://java.net/jira/browse/GLASSFISHPLUGINS-307

Hope James message would help.

+1
source share

Although it is not obvious from the published code, if it is a solution, but the symptoms are the same.

This seems to happen when creating the entity manager from the factory entity manager outside the container. factory must be closed when deployed. That's why it only works for the first time during deployment, and not when redeploying. See: Unknown entity bean class problem with glassfish v3

+1
source share

Turns out we don't need any JPA 2.0 features at this time, and the eclipselink support for Glassfish v2 is a bit spotty. So the solution for us was to return to toplink and JPA 1.0. Not the best solution, but it solved deployment problems. We will look at eclipselink when we move on to glass v3.

0
source share

I also got this problem in a web service that retrieves data from a database. I chose two solutions: (1) The solution was to put the method in webservice, for example @PreDestroy public void destruct () ==> Here I closed the EntityManagerFactory (2) The entered listener ServletContextListener and the closed open emf are also here if the webservice method could not work for any reason.

Since rebooting the server for redeployment is unacceptable, I wanted to be on the safer side by closing emf twice, if it remains open, it has a chance to close in the listener.

Thanks Nitin

0
source share

All Articles