JPA实体序列化需要实体管理器,延迟加载不应该成为问题

发布于 2024-11-08 22:39:27 字数 21400 浏览 0 评论 0原文

我不知何故收到“会话已关闭”异常。当序列化由 hibernate 支持的 JPA2 实体以获取 JSON 时。

我可以理解是否涉及延迟加载,但没有连接列。

此外,将对象序列化为 JSON 的工具允许包含和排除参数,您只需明确说明对象的哪些部分将被序列化或不会被序列化。如果我手动包含对象的所有属性,那么序列化就会起作用。然而,这是非常乏味的,我应该能够说“objectName.*”并让它递归序列化。

唯一有意义的是,该对象以某种方式具有某种调用休眠实体管理器的属性,但不是该类的可见属性之一?

Struts2 打印出以下错误:

Struts Problem Report

Struts has detected an unhandled exception:
Messages:   

    Session is closed!
    java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException

File:   org/hibernate/impl/AbstractSessionImpl.java

异常:

org.hibernate.SessionException: Session is closed!

    org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72)
    org.hibernate.impl.SessionImpl.getJDBCContext(SessionImpl.java:2000)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:234)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.add(JSONWriter.java:336)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:235)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.add(JSONWriter.java:336)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:235)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.add(JSONWriter.java:336)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:235)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.write(JSONWriter.java:98)
    org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)
    org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
    com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
    com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
    com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
    com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
    com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    java.lang.Thread.run(Thread.java:619)

这是实体:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aerose.mz.db.co05in;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author ken
 */
@Entity
@Table(name = "INTBLMST")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Intblmst.findAll", query = "SELECT i FROM Intblmst i"),
    @NamedQuery(name = "Intblmst.findByTblid", query = "SELECT i FROM Intblmst i WHERE i.intblmstPK.tblid = :tblid"),
    @NamedQuery(name = "Intblmst.findByTblcd", query = "SELECT i FROM Intblmst i WHERE i.intblmstPK.tblcd = :tblcd"),
    @NamedQuery(name = "Intblmst.findByTblsta", query = "SELECT i FROM Intblmst i WHERE i.tblsta = :tblsta"),
    @NamedQuery(name = "Intblmst.findByTblds1", query = "SELECT i FROM Intblmst i WHERE i.tblds1 = :tblds1"),
    @NamedQuery(name = "Intblmst.findByTblds2", query = "SELECT i FROM Intblmst i WHERE i.tblds2 = :tblds2"),
    @NamedQuery(name = "Intblmst.findByTblamt", query = "SELECT i FROM Intblmst i WHERE i.tblamt = :tblamt"),
    @NamedQuery(name = "Intblmst.findByTblfg1", query = "SELECT i FROM Intblmst i WHERE i.tblfg1 = :tblfg1"),
    @NamedQuery(name = "Intblmst.findByTblfg2", query = "SELECT i FROM Intblmst i WHERE i.tblfg2 = :tblfg2"),
    @NamedQuery(name = "Intblmst.findByTblfg3", query = "SELECT i FROM Intblmst i WHERE i.tblfg3 = :tblfg3"),
    @NamedQuery(name = "Intblmst.findByTblecn", query = "SELECT i FROM Intblmst i WHERE i.tblecn = :tblecn"),
    @NamedQuery(name = "Intblmst.findByTbledt", query = "SELECT i FROM Intblmst i WHERE i.tbledt = :tbledt"),
    @NamedQuery(name = "Intblmst.findByTblacn", query = "SELECT i FROM Intblmst i WHERE i.tblacn = :tblacn"),
    @NamedQuery(name = "Intblmst.findByTbladt", query = "SELECT i FROM Intblmst i WHERE i.tbladt = :tbladt"),
    @NamedQuery(name = "Intblmst.findByTblaus", query = "SELECT i FROM Intblmst i WHERE i.tblaus = :tblaus"),
    @NamedQuery(name = "Intblmst.findByTblmcn", query = "SELECT i FROM Intblmst i WHERE i.tblmcn = :tblmcn"),
    @NamedQuery(name = "Intblmst.findByTblmdt", query = "SELECT i FROM Intblmst i WHERE i.tblmdt = :tblmdt"),
    @NamedQuery(name = "Intblmst.findByTblmus", query = "SELECT i FROM Intblmst i WHERE i.tblmus = :tblmus"),
    @NamedQuery(name = "Intblmst.findByAdded", query = "SELECT i FROM Intblmst i WHERE i.added = :added"),
    @NamedQuery(name = "Intblmst.findByModified", query = "SELECT i FROM Intblmst i WHERE i.modified = :modified")})
public class Intblmst implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected IntblmstPK intblmstPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLSTA", nullable = false)
    private char tblsta;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 60)
    @Column(name = "TBLDS1", nullable = false, length = 60)
    private String tblds1;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 25)
    @Column(name = "TBLDS2", nullable = false, length = 25)
    private String tblds2;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLAMT", nullable = false)
    private long tblamt;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLFG1", nullable = false)
    @Size(max = 1)
    private String tblfg1;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "TBLFG2", nullable = false, length = 5)
    private String tblfg2;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "TBLFG3", nullable = false, length = 10)
    private String tblfg3;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLECN", nullable = false)
    private long tblecn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLEDT", nullable = false)
    private long tbledt;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLACN", nullable = false)
    private long tblacn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLADT", nullable = false)
    private long tbladt;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "TBLAUS", nullable = false, length = 10)
    private String tblaus;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLMCN", nullable = false)
    private long tblmcn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLMDT", nullable = false)
    private long tblmdt;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "TBLMUS", nullable = false, length = 10)
    private String tblmus;
    @Column(name = "Added")
    @Temporal(TemporalType.TIMESTAMP)
    private Date added;
    @Column(name = "Modified")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modified;

    public Intblmst() {
    }

    public Intblmst(IntblmstPK intblmstPK) {
        this.intblmstPK = intblmstPK;
    }

    public Intblmst(IntblmstPK intblmstPK, char tblsta, String tblds1, String tblds2, long tblamt, String tblfg1, String tblfg2, String tblfg3, long tblecn, long tbledt, long tblacn, long tbladt, String tblaus, long tblmcn, long tblmdt, String tblmus) {
        this.intblmstPK = intblmstPK;
        this.tblsta = tblsta;
        this.tblds1 = tblds1;
        this.tblds2 = tblds2;
        this.tblamt = tblamt;
        this.tblfg1 = tblfg1;
        this.tblfg2 = tblfg2;
        this.tblfg3 = tblfg3;
        this.tblecn = tblecn;
        this.tbledt = tbledt;
        this.tblacn = tblacn;
        this.tbladt = tbladt;
        this.tblaus = tblaus;
        this.tblmcn = tblmcn;
        this.tblmdt = tblmdt;
        this.tblmus = tblmus;
    }

    public Intblmst(String tblid, String tblcd) {
        this.intblmstPK = new IntblmstPK(tblid, tblcd);
    }

    public IntblmstPK getIntblmstPK() {
        return intblmstPK;
    }

    public void setIntblmstPK(IntblmstPK intblmstPK) {
        this.intblmstPK = intblmstPK;
    }

    public char getTblsta() {
        return tblsta;
    }

    public void setTblsta(char tblsta) {
        this.tblsta = tblsta;
    }

    public String getTblds1() {
        return tblds1;
    }

    public void setTblds1(String tblds1) {
        this.tblds1 = tblds1;
    }

    public String getTblds2() {
        return tblds2;
    }

    public void setTblds2(String tblds2) {
        this.tblds2 = tblds2;
    }

    public long getTblamt() {
        return tblamt;
    }

    public void setTblamt(long tblamt) {
        this.tblamt = tblamt;
    }

    public String getTblfg1() {
        return tblfg1;
    }

    public void setTblfg1(String tblfg1) {
        this.tblfg1 = tblfg1;
    }

    public String getTblfg2() {
        return tblfg2;
    }

    public void setTblfg2(String tblfg2) {
        this.tblfg2 = tblfg2;
    }

    public String getTblfg3() {
        return tblfg3;
    }

    public void setTblfg3(String tblfg3) {
        this.tblfg3 = tblfg3;
    }

    public long getTblecn() {
        return tblecn;
    }

    public void setTblecn(long tblecn) {
        this.tblecn = tblecn;
    }

    public long getTbledt() {
        return tbledt;
    }

    public void setTbledt(long tbledt) {
        this.tbledt = tbledt;
    }

    public long getTblacn() {
        return tblacn;
    }

    public void setTblacn(long tblacn) {
        this.tblacn = tblacn;
    }

    public long getTbladt() {
        return tbladt;
    }

    public void setTbladt(long tbladt) {
        this.tbladt = tbladt;
    }

    public String getTblaus() {
        return tblaus;
    }

    public void setTblaus(String tblaus) {
        this.tblaus = tblaus;
    }

    public long getTblmcn() {
        return tblmcn;
    }

    public void setTblmcn(long tblmcn) {
        this.tblmcn = tblmcn;
    }

    public long getTblmdt() {
        return tblmdt;
    }

    public void setTblmdt(long tblmdt) {
        this.tblmdt = tblmdt;
    }

    public String getTblmus() {
        return tblmus;
    }

    public void setTblmus(String tblmus) {
        this.tblmus = tblmus;
    }

    public Date getAdded() {
        return added;
    }

    public void setAdded(Date added) {
        this.added = added;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (intblmstPK != null ? intblmstPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Intblmst)) {
            return false;
        }
        Intblmst other = (Intblmst) object;
        if ((this.intblmstPK == null && other.intblmstPK != null) || (this.intblmstPK != null && !this.intblmstPK.equals(other.intblmstPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.aerose.mz.db.co05in.Intblmst[ intblmstPK=" + intblmstPK + " ]";
    }

}

这是嵌入式 ID:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aerose.mz.db.co05in;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author ken
 */
@Embeddable
public class IntblmstPK implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "TBLID", nullable = false, length = 5)
    private String tblid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 8)
    @Column(name = "TBLCD", nullable = false, length = 8)
    private String tblcd;

    public IntblmstPK() {
    }

    public IntblmstPK(String tblid, String tblcd) {
        this.tblid = tblid;
        this.tblcd = tblcd;
    }

    public String getTblid() {
        return tblid;
    }

    public void setTblid(String tblid) {
        this.tblid = tblid;
    }

    public String getTblcd() {
        return tblcd;
    }

    public void setTblcd(String tblcd) {
        this.tblcd = tblcd;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (tblid != null ? tblid.hashCode() : 0);
        hash += (tblcd != null ? tblcd.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof IntblmstPK)) {
            return false;
        }
        IntblmstPK other = (IntblmstPK) object;
        if ((this.tblid == null && other.tblid != null) || (this.tblid != null && !this.tblid.equals(other.tblid))) {
            return false;
        }
        if ((this.tblcd == null && other.tblcd != null) || (this.tblcd != null && !this.tblcd.equals(other.tblcd))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.aerose.mz.db.co05in.IntblmstPK[ tblid=" + tblid + ", tblcd=" + tblcd + " ]";
    }

}

I am somehow getting a "Session is closed" exception. When serializing an a JPA2 entity backed by hibernate for JSON.

I could understand if lazy loading were involved but there are no join columns.

Further the tool that serializes the object to JSON allows for include and exclude parameters, simply you can explicitly state what parts of the object will or will not be serialized. If I manually include all properties of the object then serialization works. However this is very tedious and I should be able to say "objectName.*" and have it recursively serialize.

The only thing that makes sense is that somehow the object has some sort of property which invokes hibernates entity manager but isn't one of the visible properties on the class?

The follow error is printed out by Struts2:

Struts Problem Report

Struts has detected an unhandled exception:
Messages:   

    Session is closed!
    java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException

File:   org/hibernate/impl/AbstractSessionImpl.java

The exception:

org.hibernate.SessionException: Session is closed!

    org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72)
    org.hibernate.impl.SessionImpl.getJDBCContext(SessionImpl.java:2000)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:234)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.add(JSONWriter.java:336)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:235)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.add(JSONWriter.java:336)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:235)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.add(JSONWriter.java:336)
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:235)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:164)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:130)
    org.apache.struts2.json.JSONWriter.write(JSONWriter.java:98)
    org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)
    org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
    com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
    com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
    com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
    com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
    com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    java.lang.Thread.run(Thread.java:619)

Here is the entity:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aerose.mz.db.co05in;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author ken
 */
@Entity
@Table(name = "INTBLMST")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Intblmst.findAll", query = "SELECT i FROM Intblmst i"),
    @NamedQuery(name = "Intblmst.findByTblid", query = "SELECT i FROM Intblmst i WHERE i.intblmstPK.tblid = :tblid"),
    @NamedQuery(name = "Intblmst.findByTblcd", query = "SELECT i FROM Intblmst i WHERE i.intblmstPK.tblcd = :tblcd"),
    @NamedQuery(name = "Intblmst.findByTblsta", query = "SELECT i FROM Intblmst i WHERE i.tblsta = :tblsta"),
    @NamedQuery(name = "Intblmst.findByTblds1", query = "SELECT i FROM Intblmst i WHERE i.tblds1 = :tblds1"),
    @NamedQuery(name = "Intblmst.findByTblds2", query = "SELECT i FROM Intblmst i WHERE i.tblds2 = :tblds2"),
    @NamedQuery(name = "Intblmst.findByTblamt", query = "SELECT i FROM Intblmst i WHERE i.tblamt = :tblamt"),
    @NamedQuery(name = "Intblmst.findByTblfg1", query = "SELECT i FROM Intblmst i WHERE i.tblfg1 = :tblfg1"),
    @NamedQuery(name = "Intblmst.findByTblfg2", query = "SELECT i FROM Intblmst i WHERE i.tblfg2 = :tblfg2"),
    @NamedQuery(name = "Intblmst.findByTblfg3", query = "SELECT i FROM Intblmst i WHERE i.tblfg3 = :tblfg3"),
    @NamedQuery(name = "Intblmst.findByTblecn", query = "SELECT i FROM Intblmst i WHERE i.tblecn = :tblecn"),
    @NamedQuery(name = "Intblmst.findByTbledt", query = "SELECT i FROM Intblmst i WHERE i.tbledt = :tbledt"),
    @NamedQuery(name = "Intblmst.findByTblacn", query = "SELECT i FROM Intblmst i WHERE i.tblacn = :tblacn"),
    @NamedQuery(name = "Intblmst.findByTbladt", query = "SELECT i FROM Intblmst i WHERE i.tbladt = :tbladt"),
    @NamedQuery(name = "Intblmst.findByTblaus", query = "SELECT i FROM Intblmst i WHERE i.tblaus = :tblaus"),
    @NamedQuery(name = "Intblmst.findByTblmcn", query = "SELECT i FROM Intblmst i WHERE i.tblmcn = :tblmcn"),
    @NamedQuery(name = "Intblmst.findByTblmdt", query = "SELECT i FROM Intblmst i WHERE i.tblmdt = :tblmdt"),
    @NamedQuery(name = "Intblmst.findByTblmus", query = "SELECT i FROM Intblmst i WHERE i.tblmus = :tblmus"),
    @NamedQuery(name = "Intblmst.findByAdded", query = "SELECT i FROM Intblmst i WHERE i.added = :added"),
    @NamedQuery(name = "Intblmst.findByModified", query = "SELECT i FROM Intblmst i WHERE i.modified = :modified")})
public class Intblmst implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected IntblmstPK intblmstPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLSTA", nullable = false)
    private char tblsta;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 60)
    @Column(name = "TBLDS1", nullable = false, length = 60)
    private String tblds1;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 25)
    @Column(name = "TBLDS2", nullable = false, length = 25)
    private String tblds2;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLAMT", nullable = false)
    private long tblamt;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLFG1", nullable = false)
    @Size(max = 1)
    private String tblfg1;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "TBLFG2", nullable = false, length = 5)
    private String tblfg2;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "TBLFG3", nullable = false, length = 10)
    private String tblfg3;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLECN", nullable = false)
    private long tblecn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLEDT", nullable = false)
    private long tbledt;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLACN", nullable = false)
    private long tblacn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLADT", nullable = false)
    private long tbladt;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "TBLAUS", nullable = false, length = 10)
    private String tblaus;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLMCN", nullable = false)
    private long tblmcn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TBLMDT", nullable = false)
    private long tblmdt;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "TBLMUS", nullable = false, length = 10)
    private String tblmus;
    @Column(name = "Added")
    @Temporal(TemporalType.TIMESTAMP)
    private Date added;
    @Column(name = "Modified")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modified;

    public Intblmst() {
    }

    public Intblmst(IntblmstPK intblmstPK) {
        this.intblmstPK = intblmstPK;
    }

    public Intblmst(IntblmstPK intblmstPK, char tblsta, String tblds1, String tblds2, long tblamt, String tblfg1, String tblfg2, String tblfg3, long tblecn, long tbledt, long tblacn, long tbladt, String tblaus, long tblmcn, long tblmdt, String tblmus) {
        this.intblmstPK = intblmstPK;
        this.tblsta = tblsta;
        this.tblds1 = tblds1;
        this.tblds2 = tblds2;
        this.tblamt = tblamt;
        this.tblfg1 = tblfg1;
        this.tblfg2 = tblfg2;
        this.tblfg3 = tblfg3;
        this.tblecn = tblecn;
        this.tbledt = tbledt;
        this.tblacn = tblacn;
        this.tbladt = tbladt;
        this.tblaus = tblaus;
        this.tblmcn = tblmcn;
        this.tblmdt = tblmdt;
        this.tblmus = tblmus;
    }

    public Intblmst(String tblid, String tblcd) {
        this.intblmstPK = new IntblmstPK(tblid, tblcd);
    }

    public IntblmstPK getIntblmstPK() {
        return intblmstPK;
    }

    public void setIntblmstPK(IntblmstPK intblmstPK) {
        this.intblmstPK = intblmstPK;
    }

    public char getTblsta() {
        return tblsta;
    }

    public void setTblsta(char tblsta) {
        this.tblsta = tblsta;
    }

    public String getTblds1() {
        return tblds1;
    }

    public void setTblds1(String tblds1) {
        this.tblds1 = tblds1;
    }

    public String getTblds2() {
        return tblds2;
    }

    public void setTblds2(String tblds2) {
        this.tblds2 = tblds2;
    }

    public long getTblamt() {
        return tblamt;
    }

    public void setTblamt(long tblamt) {
        this.tblamt = tblamt;
    }

    public String getTblfg1() {
        return tblfg1;
    }

    public void setTblfg1(String tblfg1) {
        this.tblfg1 = tblfg1;
    }

    public String getTblfg2() {
        return tblfg2;
    }

    public void setTblfg2(String tblfg2) {
        this.tblfg2 = tblfg2;
    }

    public String getTblfg3() {
        return tblfg3;
    }

    public void setTblfg3(String tblfg3) {
        this.tblfg3 = tblfg3;
    }

    public long getTblecn() {
        return tblecn;
    }

    public void setTblecn(long tblecn) {
        this.tblecn = tblecn;
    }

    public long getTbledt() {
        return tbledt;
    }

    public void setTbledt(long tbledt) {
        this.tbledt = tbledt;
    }

    public long getTblacn() {
        return tblacn;
    }

    public void setTblacn(long tblacn) {
        this.tblacn = tblacn;
    }

    public long getTbladt() {
        return tbladt;
    }

    public void setTbladt(long tbladt) {
        this.tbladt = tbladt;
    }

    public String getTblaus() {
        return tblaus;
    }

    public void setTblaus(String tblaus) {
        this.tblaus = tblaus;
    }

    public long getTblmcn() {
        return tblmcn;
    }

    public void setTblmcn(long tblmcn) {
        this.tblmcn = tblmcn;
    }

    public long getTblmdt() {
        return tblmdt;
    }

    public void setTblmdt(long tblmdt) {
        this.tblmdt = tblmdt;
    }

    public String getTblmus() {
        return tblmus;
    }

    public void setTblmus(String tblmus) {
        this.tblmus = tblmus;
    }

    public Date getAdded() {
        return added;
    }

    public void setAdded(Date added) {
        this.added = added;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (intblmstPK != null ? intblmstPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Intblmst)) {
            return false;
        }
        Intblmst other = (Intblmst) object;
        if ((this.intblmstPK == null && other.intblmstPK != null) || (this.intblmstPK != null && !this.intblmstPK.equals(other.intblmstPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.aerose.mz.db.co05in.Intblmst[ intblmstPK=" + intblmstPK + " ]";
    }

}

Here is the Embedded ID:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aerose.mz.db.co05in;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author ken
 */
@Embeddable
public class IntblmstPK implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "TBLID", nullable = false, length = 5)
    private String tblid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 8)
    @Column(name = "TBLCD", nullable = false, length = 8)
    private String tblcd;

    public IntblmstPK() {
    }

    public IntblmstPK(String tblid, String tblcd) {
        this.tblid = tblid;
        this.tblcd = tblcd;
    }

    public String getTblid() {
        return tblid;
    }

    public void setTblid(String tblid) {
        this.tblid = tblid;
    }

    public String getTblcd() {
        return tblcd;
    }

    public void setTblcd(String tblcd) {
        this.tblcd = tblcd;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (tblid != null ? tblid.hashCode() : 0);
        hash += (tblcd != null ? tblcd.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof IntblmstPK)) {
            return false;
        }
        IntblmstPK other = (IntblmstPK) object;
        if ((this.tblid == null && other.tblid != null) || (this.tblid != null && !this.tblid.equals(other.tblid))) {
            return false;
        }
        if ((this.tblcd == null && other.tblcd != null) || (this.tblcd != null && !this.tblcd.equals(other.tblcd))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.aerose.mz.db.co05in.IntblmstPK[ tblid=" + tblid + ", tblcd=" + tblcd + " ]";
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秉烛思 2024-11-15 22:39:27

It looks like JSON serializer encountered a lazy proxy and tries to serialize its lazy initialization handler obtained from calling HibernateProxy.getHibernateLazyInitializer(). You can try to configure your JSON serializer to ignore that method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文