项目中,父层是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;
} }

【jackson 异常】com.fasterxml.jackson.databind.JsonMappingException异常处理的更多相关文章

  1. SpringBoot JPA懒加载异常 - com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy

    问题与分析 某日忽然发现在用postman测试数据时报错如下: com.fasterxml.jackson.databind.JsonMappingException: could not initi ...

  2. 400 bad Request: JackSon将json串转成List<Object>,异常com.fasterxml.jackson.databind.JsonMappingException

    最近遇到的400, 以前总以为 400 就是参数不匹配造成的,直到今天遇到这个问题 控制台报错如下:  com.fasterxml.jackson.databind.JsonMappingExcept ...

  3. com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

    作者原创,转载请注明转载地址 第一次遇到该异常,在网上搜了很长时间也没找到解决答案,特此记录 1.异常展示: com.fasterxml.jackson.databind.JsonMappingExc ...

  4. JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of j

    异常信息如下: JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token ...

  5. com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 异常

    分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自分享牛http://blog.csdn.net/qq_30739519) 1.1.1. 前言 近期在使用ObjectMapper对象将jso ...

  6. HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite

    org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r ...

  7. JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc

    代码程序: @PostMapping("selectById") @ResponseBody public Result selectById(@RequestBody int i ...

  8. java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper

    RabbitMq配置时常见错误 java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper <de ...

  9. com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ExceptionId"

    com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Exception ...

随机推荐

  1. 禁用visual studio实时调试器

    最近每次开机时都会出来一个visual Studio实时调试器,报“发生了未处理的异常(‘System ComponentModel.Win32Exception’,发生位置是 BSSocketSms ...

  2. InnoDB O_DIRECT选项漫谈(一)【转】

    本文来自:http://insidemysql.blog.163.com/blog/static/2028340422013671186977/   最近和文件系统内核开发人员做技术交流,对O_DIR ...

  3. 【python】多进程学习

    来源:廖雪峰 讲解看来源吧 把例子记一下 1.用fork创建进程 import os print "Process (%s) start..." % os.getpid() pid ...

  4. xcode运行push通知总是提示输入用户名和密码

    xcode运行push通知总是提示输入用户名和密码,目前找到的解决方案是,  打开钥匙串,然后找到push证书下面的私有密钥,双击进入将访问控制设置为允许全部访问,即可.

  5. XStream xml to bean

    <!-- pom.xml --> <dependency> <groupId>com.thoughtworks.xstream</groupId> &l ...

  6. 设计模式之构建者模式(Builder):初步理解

    构建者(Builder)设计模式(又叫生成器设计模式): 当一个类的内部数据过于复杂的时候(通常是负责持有数据的类,比如Config.VO.PO.Entity...),要创建的话可能就需要了解这个类的 ...

  7. php 审核管理

    权限管理界面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  8. CLR via C#(13)-浅谈事件

    提起事件,我们都不陌生,事件使类之间有了交互的能力.它是建立在委托基础上的.有了前面对委托的了解,相信读起事件来也不会太难了.关于事件,现成的好文章数不胜数,本不打算写了.不过问道有先后,各抒己见,也 ...

  9. 数据结构和算法 – 6.构建字典: DictionaryBase 类和 SortedList 类

      6.1.DictionaryBase 类的基础方法和属性 大家可以把字典数据结构看成是一种计算机化的词典.要查找的词就是关键字,而词的定义就是值. DictionaryBase 类是一种用作专有字 ...

  10. Jcapta

    http://blog.csdn.net/shadowsick/article/details/8575471