Я получаю исключение "Сессия закрыта".При сериализации сущности JPA2, поддерживаемой hibernate для 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 + " ]";
}
}
Вот код для встраивания:
/*
* 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 + " ]";
}
}