项目中,父层是Gene.java【基因实体】 子层是Corlib.java【文集库实体】,一种基因对用多个文集库文章
但是在查询文集库这个实体的时候报错:【com.fasterxml.jackson.databind.JsonMappingException】
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.agen.entity.Corlib["gene"]->com.agen.entity.Gene_$$_jvstb50_3["handler"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275)
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1109)
at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1134)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3672)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3048)
at com.agen.controller.CorlibController.queryAllcorlib(CorlibController.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.agen.util.LoginFilter.doFilter(LoginFilter.java:58)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1778)
at java.lang.Thread.run(Thread.java:745)
错误描述:
Could not write content: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
由于会发生 循环引用的问题,因此在实体中进行了截断即子层可以查到父层的信息,但是父层查不到子层的信息。
解决问题:
Corlib.java的实体类中Gene字段的处理本来是:
将其修改为:
即可!!
附带给上这两个实体的代码:
Gene.java的代码:
package com.agen.entity; import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set; import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /**
* Gene entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "gene", catalog = "biologyinfo")
public class Gene implements java.io.Serializable { // Fields private String geneId;
private Disease disease;
private String geneName;
private String location;
private String snp;
private String position;
private String allele;
private String influence;
private String riskAllele;
private String alleleFrequency;
private String genotypeModel;
private String genotypeFrequency;
private String orhrvalue;
private String minorAllele;
private String caseNum;
private String controlNum;
private String flankingSequence;
private String foreignPublished;
private String hapMap;
private String theE;
private String alterSite;
private String alterSiteRisk;
private String geneCre;
private Timestamp createDate;
private Timestamp updateDate;
private String transPerson;
private Set<Corlib> corlibs = new HashSet<Corlib>(0); // Constructors /** default constructor */
public Gene() {
} /** minimal constructor */
public Gene(Disease disease) {
this.disease = disease;
} /** full constructor */
public Gene(Disease disease, String geneName, String location, String snp,
String position, String allele, String influence,
String riskAllele, String alleleFrequency, String genotypeModel,
String genotypeFrequency, String orhrvalue, String minorAllele,
String caseNum, String controlNum, String flankingSequence,
String foreignPublished, String hapMap, String theE,
String alterSite, String alterSiteRisk, String geneCre,
Timestamp createDate, Timestamp updateDate, String transPerson,
Set<Corlib> corlibs) {
this.disease = disease;
this.geneName = geneName;
this.location = location;
this.snp = snp;
this.position = position;
this.allele = allele;
this.influence = influence;
this.riskAllele = riskAllele;
this.alleleFrequency = alleleFrequency;
this.genotypeModel = genotypeModel;
this.genotypeFrequency = genotypeFrequency;
this.orhrvalue = orhrvalue;
this.minorAllele = minorAllele;
this.caseNum = caseNum;
this.controlNum = controlNum;
this.flankingSequence = flankingSequence;
this.foreignPublished = foreignPublished;
this.hapMap = hapMap;
this.theE = theE;
this.alterSite = alterSite;
this.alterSiteRisk = alterSiteRisk;
this.geneCre = geneCre;
this.createDate = createDate;
this.updateDate = updateDate;
this.transPerson = transPerson;
this.corlibs = corlibs;
} // Property accessors
@GenericGenerator(name = "generator", strategy = "uuid.hex")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "geneID", unique = true, nullable = false, length = 36)
public String getGeneId() {
return this.geneId;
} public void setGeneId(String geneId) {
this.geneId = geneId;
} @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "diseaseId", nullable = false)
public Disease getDisease() {
return this.disease;
} public void setDisease(Disease disease) {
this.disease = disease;
} @Column(name = "geneName", length = 30)
public String getGeneName() {
return this.geneName;
} public void setGeneName(String geneName) {
this.geneName = geneName;
} @Column(name = "location", length = 30)
public String getLocation() {
return this.location;
} public void setLocation(String location) {
this.location = location;
} @Column(name = "SNP", length = 30)
public String getSnp() {
return this.snp;
} public void setSnp(String snp) {
this.snp = snp;
} @Column(name = "position", length = 30)
public String getPosition() {
return this.position;
} public void setPosition(String position) {
this.position = position;
} @Column(name = "allele", length = 30)
public String getAllele() {
return this.allele;
} public void setAllele(String allele) {
this.allele = allele;
} @Column(name = "influence", length = 30)
public String getInfluence() {
return this.influence;
} public void setInfluence(String influence) {
this.influence = influence;
} @Column(name = "riskAllele", length = 3)
public String getRiskAllele() {
return this.riskAllele;
} public void setRiskAllele(String riskAllele) {
this.riskAllele = riskAllele;
} @Column(name = "alleleFrequency", length = 30)
public String getAlleleFrequency() {
return this.alleleFrequency;
} public void setAlleleFrequency(String alleleFrequency) {
this.alleleFrequency = alleleFrequency;
} @Column(name = "genotypeModel", length = 30)
public String getGenotypeModel() {
return this.genotypeModel;
} public void setGenotypeModel(String genotypeModel) {
this.genotypeModel = genotypeModel;
} @Column(name = "genotypeFrequency", length = 30)
public String getGenotypeFrequency() {
return this.genotypeFrequency;
} public void setGenotypeFrequency(String genotypeFrequency) {
this.genotypeFrequency = genotypeFrequency;
} @Column(name = "oRHRvalue", length = 30)
public String getOrhrvalue() {
return this.orhrvalue;
} public void setOrhrvalue(String orhrvalue) {
this.orhrvalue = orhrvalue;
} @Column(name = "minorAllele", length = 30)
public String getMinorAllele() {
return this.minorAllele;
} public void setMinorAllele(String minorAllele) {
this.minorAllele = minorAllele;
} @Column(name = "caseNum", length = 30)
public String getCaseNum() {
return this.caseNum;
} public void setCaseNum(String caseNum) {
this.caseNum = caseNum;
} @Column(name = "controlNum", length = 30)
public String getControlNum() {
return this.controlNum;
} public void setControlNum(String controlNum) {
this.controlNum = controlNum;
} @Column(name = "flankingSequence", length = 300)
public String getFlankingSequence() {
return this.flankingSequence;
} public void setFlankingSequence(String flankingSequence) {
this.flankingSequence = flankingSequence;
} @Column(name = "foreignPublished", length = 30)
public String getForeignPublished() {
return this.foreignPublished;
} public void setForeignPublished(String foreignPublished) {
this.foreignPublished = foreignPublished;
} @Column(name = "hapMap", length = 30)
public String getHapMap() {
return this.hapMap;
} public void setHapMap(String hapMap) {
this.hapMap = hapMap;
} @Column(name = "theE", length = 30)
public String getTheE() {
return this.theE;
} public void setTheE(String theE) {
this.theE = theE;
} @Column(name = "alterSite", length = 30)
public String getAlterSite() {
return this.alterSite;
} public void setAlterSite(String alterSite) {
this.alterSite = alterSite;
} @Column(name = "alterSiteRisk", length = 30)
public String getAlterSiteRisk() {
return this.alterSiteRisk;
} public void setAlterSiteRisk(String alterSiteRisk) {
this.alterSiteRisk = alterSiteRisk;
} @Column(name = "geneCre", length = 500)
public String getGeneCre() {
return this.geneCre;
} public void setGeneCre(String geneCre) {
this.geneCre = geneCre;
} @Column(name = "createDate", length = 19)
public Timestamp getCreateDate() {
return this.createDate;
} public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
} @Column(name = "updateDate", length = 19)
public Timestamp getUpdateDate() {
return this.updateDate;
} public void setUpdateDate(Timestamp updateDate) {
this.updateDate = updateDate;
} @Column(name = "transPerson", length = 36)
public String getTransPerson() {
return this.transPerson;
} public void setTransPerson(String transPerson) {
this.transPerson = transPerson;
} @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "gene")
public Set<Corlib> getCorlibs() {
return this.corlibs;
} public void setCorlibs(Set<Corlib> corlibs) {
this.corlibs = corlibs;
} }
Corlib.java的代码:
package com.agen.entity; import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator; /**
* Corlib entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "corlib", catalog = "biologyinfo")
public class Corlib implements java.io.Serializable { // Fields private String corlibId;
private Gene gene;
private String corlibContext;
private String corlibCre;
private Timestamp createDate;
private Timestamp updateDate;
private String transPerson; // Constructors /** default constructor */
public Corlib() {
} /** minimal constructor */
public Corlib(Gene gene) {
this.gene = gene;
} /** full constructor */
public Corlib(Gene gene, String corlibContext, String corlibCre,
Timestamp createDate, Timestamp updateDate, String transPerson) {
this.gene = gene;
this.corlibContext = corlibContext;
this.corlibCre = corlibCre;
this.createDate = createDate;
this.updateDate = updateDate;
this.transPerson = transPerson;
} // Property accessors
@GenericGenerator(name = "generator", strategy = "uuid.hex")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "corlibId", unique = true, nullable = false, length = 36)
public String getCorlibId() {
return this.corlibId;
} public void setCorlibId(String corlibId) {
this.corlibId = corlibId;
} @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "geneID", nullable = false)
public Gene getGene() {
return this.gene;
} public void setGene(Gene gene) {
this.gene = gene;
} @Column(name = "corlibContext", length = 65535)
public String getCorlibContext() {
return this.corlibContext;
} public void setCorlibContext(String corlibContext) {
this.corlibContext = corlibContext;
} @Column(name = "corlibCre", length = 500)
public String getCorlibCre() {
return this.corlibCre;
} public void setCorlibCre(String corlibCre) {
this.corlibCre = corlibCre;
} @Column(name = "createDate", length = 19)
public Timestamp getCreateDate() {
return this.createDate;
} public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
} @Column(name = "updateDate", length = 19)
public Timestamp getUpdateDate() {
return this.updateDate;
} public void setUpdateDate(Timestamp updateDate) {
this.updateDate = updateDate;
} @Column(name = "transPerson", length = 36)
public String getTransPerson() {
return this.transPerson;
} public void setTransPerson(String transPerson) {
this.transPerson = transPerson;
} }