热部署后的未知实体bean类:netbeans 6.9 + glassfish 2.1 + eclipselink jpa 2.0

时间:2010-12-07 21:02:28

标签: java jpa java-ee eclipselink netbeans-6.9

当我部署我的应用程序时,它完美运行,直到我进行更改,保存,并且netbeans热部署应用程序。此时,我在具有@entity的类上得到了一个未知的实体bean类错误,并且它包含在我的persistence.xml中。发生这种情况时,任何与jpa有关的事都会停止工作。只有当我重新启动服务器时,我的jpa内容才会重新开始工作。

如果我在项目中将save部署为save,而我只手动保存和部署,我会得到相同的结果。

这只是一个netbeans / glassfish错误吗?或者我的jpa设置有问题吗?


的异常
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)

实体

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

<?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>

更新

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>

5 个答案:

答案 0 :(得分:2)

问题是旧的持久性单元在重新部署后仍然会引用旧类。确保旧的EntityManagerFactory已关闭。 Glassfish应该为任何托管工厂(如SessionBean)处理此问题,但如果您管理自己的工厂,则需要确保这些工厂已关闭。

答案 1 :(得分:1)

你的问题非常有趣。所以,我只是继续阅读更多相关内容。我在SO本身发现了一个线程,它仍然没有任何解决方案JPA - Unknown entity bean class。不仅在SO,还有一些外面的论坛,如:

过了一会儿,我发现SO的另一个主题是“ Java Persistance Issue

质疑&amp;由James本身回答:

  

因此,上述评论表明了这一点   这似乎与日食有关   插入玻璃鱼。我没有   部署耳朵时的问题   手动

     

感谢大家的帮助。

     

詹姆斯

最后,这听起来像一个问题:) http://java.net/jira/browse/GLASSFISHPLUGINS-307

希望,詹姆斯的消息会有所帮助。

答案 2 :(得分:1)

虽然从发布的代码中看不出这是否是解决方案,但症状是相同的。

从容器外部的实体管理器工厂创建实体管理器时似乎会发生这种情况。工厂需要在取消部署时关闭。这就是为什么它只在部署时第一次工作而不是重新部署。请参阅:Unknown entity bean class issue with glassfish v3

答案 3 :(得分:0)

原来我们此时并不需要任何JPA 2.0功能,而且eclipselink对glassfish v2的支持有点不稳定。所以我们的解决方案是切换回toplink和JPA 1.0。不是最佳解决方案,但它解决了我们的部署问题。当我们切换到glassfish v3时,我们将关注eclipselink。

答案 4 :(得分:0)

我在从数据库中获取数据的Web服务中也遇到了这个问题。 我选择了两种解决方案: - (1)解决方案是将一个方法放在webservice中     @PreDestroy     public void destruct()==&gt;这里我关闭了EntityManagerFactory (2)在这里引入了一个监听器ServletContextListener并关闭了open emf,万一webservice方法由于任何原因无法工作。

因为重新部署的服务器重启是不可接受的,所以我希望处于更安全的一边,关闭emf两次,以防它保持打开状态,它有机会在监听器中关闭。

由于 尼丁