当前位置: 首页 > 面试题库 >

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

林国安
2023-03-14
问题内容

当我部署应用程序时,它可以完美工作,直到我进行更改,保存并由Netbeans热部署该应用程序为止。此时,我在具有@entity的类上收到了一个未知的实体bean类错误,它包含在我的persistence.xml中。发生这种情况时,处理jpa的所有内容都会停止工作。只有重新启动服务器后,我的jpa内容才能再次开始工作。

如果我在项目中关闭了部署保存功能,而仅手动保存和部署,我将得到相同的结果。

这仅仅是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>

问题答案:

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



 类似资料:
  • 问题内容: 我正在尝试入门Hibernate 2nd Edition,而我一直试图将简单的工作示例与HSQLDB结合在一起。 当我跑步时,我得到 这是我得到的: Message.java PopulateMessages.java build.properties hibernate.cfg.xml build.xml 问题答案: 您的实体注释不正确, 必须 使用注释。您可以使用Hibernate

  • 问题内容: 我真的很想了解我的代码发生了什么。 我有一个独立的应用程序,它使用spring和Hibernate作为JPA,我正在尝试使用单个主类运行测试 我的主班 我的应用程序上下文是: 我的用户模型是: 我的DAO是: 这是我运行程序时出现的我的stacktrace错误: 问题答案: 您必须在会话工厂配置中列出您的类。如果使用,则可以自动发现实体。 为了在hibernate和spring中使用注

  • 我有一个测试车, 而applicatin.xml是 但它报告异常 java.lang.IllegalArgumentException:未知实体:com.chinalbs.entity.conductor(位于org.hibernate.ejb.abstractentyManagerImpl.persist(abstractentyManagerImpl.java:842)(位于sun.refle

  • 应用更新部署无需reload或者restarthi-nginx。hi-nginx-java能根据全局配置 route { lrucache { reflect { expires = 300 size = 1024 } } } 自动实现热更新。关键值由"route.lrucache.reflect.e

  • 本文向大家介绍Spring Boot实现热部署的实例方法,包括了Spring Boot实现热部署的实例方法的使用技巧和注意事项,需要的朋友参考一下 Spring Boot怎么实现热部署 在Spring Boot实现代码热部署是一件很简单的事情,代码的修改可以自动部署并重新热启动项目。 1、引用devtools依赖 这样,当修改一个java类时就会热更新。 2、自定义配置热部署 以下配置用于自定义配

  • 问题内容: 我正在尝试使用注释将Spring与Hibernate结合使用,并且出现以下错误: 这是我的设置… 我的实体: 我的豆子: } 我在Spring中启用注释: 当我通过BlazeDS从Flex应用程序调用Foo.addBar方法时收到错误消息。 我真的很想避免其他配置,而且似乎所有这些都可以解决。 我正在使用Spring 3.0.0.RC1,Hibernate Annotations 3.