项目中,父层是Gene.java【基因实体】 子层是Corlib.java【文集库实体】,一种基因对用多个文集库文章
但是在查询文集库这个实体的时候报错:【com.fasterxml.jackson.databind.JsonMappingException】
1 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"]) 2 at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275) 3 at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1109) 4 at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1134) 5 at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69) 6 at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32) 7 at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693) 8 at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) 9 at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) 10 at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693) 11 at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690) 12 at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) 13 at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292) 14 at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3672) 15 at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3048) 16 at com.agen.controller.CorlibController.queryAllcorlib(CorlibController.java:78) 17 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 18 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 19 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 20 at java.lang.reflect.Method.invoke(Method.java:606) 21 at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 22 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) 23 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 24 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777) 25 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) 26 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 27 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) 28 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) 29 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 30 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) 31 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) 32 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) 33 at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 34 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 35 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 36 at com.agen.util.LoginFilter.doFilter(LoginFilter.java:58) 37 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 38 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 39 at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150) 40 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 41 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 42 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 43 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 44 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 45 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 46 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 47 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 48 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 49 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 50 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 51 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 52 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 53 at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879) 54 at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617) 55 at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1778) 56 at java.lang.Thread.run(Thread.java:745)
View Code
错误描述:
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的代码:
1 package com.agen.entity; 2 3 import java.sql.Timestamp; 4 import java.util.HashSet; 5 import java.util.Set; 6 7 import javax.persistence.CascadeType; 8 import javax.persistence.Column; 9 import javax.persistence.Entity; 10 import javax.persistence.FetchType; 11 import javax.persistence.GeneratedValue; 12 import javax.persistence.Id; 13 import javax.persistence.JoinColumn; 14 import javax.persistence.ManyToOne; 15 import javax.persistence.OneToMany; 16 import javax.persistence.Table; 17 18 import org.hibernate.annotations.GenericGenerator; 19 20 import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 22 /** 23 * Gene entity. @author MyEclipse Persistence Tools 24 */ 25 @Entity 26 @Table(name = "gene", catalog = "biologyinfo") 27 public class Gene implements java.io.Serializable { 28 29 // Fields 30 31 private String geneId; 32 private Disease disease; 33 private String geneName; 34 private String location; 35 private String snp; 36 private String position; 37 private String allele; 38 private String influence; 39 private String riskAllele; 40 private String alleleFrequency; 41 private String genotypeModel; 42 private String genotypeFrequency; 43 private String orhrvalue; 44 private String minorAllele; 45 private String caseNum; 46 private String controlNum; 47 private String flankingSequence; 48 private String foreignPublished; 49 private String hapMap; 50 private String theE; 51 private String alterSite; 52 private String alterSiteRisk; 53 private String geneCre; 54 private Timestamp createDate; 55 private Timestamp updateDate; 56 private String transPerson; 57 private Set<Corlib> corlibs = new HashSet<Corlib>(0); 58 59 // Constructors 60 61 /** default constructor */ 62 public Gene() { 63 } 64 65 /** minimal constructor */ 66 public Gene(Disease disease) { 67 this.disease = disease; 68 } 69 70 /** full constructor */ 71 public Gene(Disease disease, String geneName, String location, String snp, 72 String position, String allele, String influence, 73 String riskAllele, String alleleFrequency, String genotypeModel, 74 String genotypeFrequency, String orhrvalue, String minorAllele, 75 String caseNum, String controlNum, String flankingSequence, 76 String foreignPublished, String hapMap, String theE, 77 String alterSite, String alterSiteRisk, String geneCre, 78 Timestamp createDate, Timestamp updateDate, String transPerson, 79 Set<Corlib> corlibs) { 80 this.disease = disease; 81 this.geneName = geneName; 82 this.location = location; 83 this.snp = snp; 84 this.position = position; 85 this.allele = allele; 86 this.influence = influence; 87 this.riskAllele = riskAllele; 88 this.alleleFrequency = alleleFrequency; 89 this.genotypeModel = genotypeModel; 90 this.genotypeFrequency = genotypeFrequency; 91 this.orhrvalue = orhrvalue; 92 this.minorAllele = minorAllele; 93 this.caseNum = caseNum; 94 this.controlNum = controlNum; 95 this.flankingSequence = flankingSequence; 96 this.foreignPublished = foreignPublished; 97 this.hapMap = hapMap; 98 this.theE = theE; 99 this.alterSite = alterSite; 100 this.alterSiteRisk = alterSiteRisk; 101 this.geneCre = geneCre; 102 this.createDate = createDate; 103 this.updateDate = updateDate; 104 this.transPerson = transPerson; 105 this.corlibs = corlibs; 106 } 107 108 // Property accessors 109 @GenericGenerator(name = "generator", strategy = "uuid.hex") 110 @Id 111 @GeneratedValue(generator = "generator") 112 @Column(name = "geneID", unique = true, nullable = false, length = 36) 113 public String getGeneId() { 114 return this.geneId; 115 } 116 117 public void setGeneId(String geneId) { 118 this.geneId = geneId; 119 } 120 121 @ManyToOne(fetch = FetchType.EAGER) 122 @JoinColumn(name = "diseaseId", nullable = false) 123 public Disease getDisease() { 124 return this.disease; 125 } 126 127 public void setDisease(Disease disease) { 128 this.disease = disease; 129 } 130 131 @Column(name = "geneName", length = 30) 132 public String getGeneName() { 133 return this.geneName; 134 } 135 136 public void setGeneName(String geneName) { 137 this.geneName = geneName; 138 } 139 140 @Column(name = "location", length = 30) 141 public String getLocation() { 142 return this.location; 143 } 144 145 public void setLocation(String location) { 146 this.location = location; 147 } 148 149 @Column(name = "SNP", length = 30) 150 public String getSnp() { 151 return this.snp; 152 } 153 154 public void setSnp(String snp) { 155 this.snp = snp; 156 } 157 158 @Column(name = "position", length = 30) 159 public String getPosition() { 160 return this.position; 161 } 162 163 public void setPosition(String position) { 164 this.position = position; 165 } 166 167 @Column(name = "allele", length = 30) 168 public String getAllele() { 169 return this.allele; 170 } 171 172 public void setAllele(String allele) { 173 this.allele = allele; 174 } 175 176 @Column(name = "influence", length = 30) 177 public String getInfluence() { 178 return this.influence; 179 } 180 181 public void setInfluence(String influence) { 182 this.influence = influence; 183 } 184 185 @Column(name = "riskAllele", length = 3) 186 public String getRiskAllele() { 187 return this.riskAllele; 188 } 189 190 public void setRiskAllele(String riskAllele) { 191 this.riskAllele = riskAllele; 192 } 193 194 @Column(name = "alleleFrequency", length = 30) 195 public String getAlleleFrequency() { 196 return this.alleleFrequency; 197 } 198 199 public void setAlleleFrequency(String alleleFrequency) { 200 this.alleleFrequency = alleleFrequency; 201 } 202 203 @Column(name = "genotypeModel", length = 30) 204 public String getGenotypeModel() { 205 return this.genotypeModel; 206 } 207 208 public void setGenotypeModel(String genotypeModel) { 209 this.genotypeModel = genotypeModel; 210 } 211 212 @Column(name = "genotypeFrequency", length = 30) 213 public String getGenotypeFrequency() { 214 return this.genotypeFrequency; 215 } 216 217 public void setGenotypeFrequency(String genotypeFrequency) { 218 this.genotypeFrequency = genotypeFrequency; 219 } 220 221 @Column(name = "oRHRvalue", length = 30) 222 public String getOrhrvalue() { 223 return this.orhrvalue; 224 } 225 226 public void setOrhrvalue(String orhrvalue) { 227 this.orhrvalue = orhrvalue; 228 } 229 230 @Column(name = "minorAllele", length = 30) 231 public String getMinorAllele() { 232 return this.minorAllele; 233 } 234 235 public void setMinorAllele(String minorAllele) { 236 this.minorAllele = minorAllele; 237 } 238 239 @Column(name = "caseNum", length = 30) 240 public String getCaseNum() { 241 return this.caseNum; 242 } 243 244 public void setCaseNum(String caseNum) { 245 this.caseNum = caseNum; 246 } 247 248 @Column(name = "controlNum", length = 30) 249 public String getControlNum() { 250 return this.controlNum; 251 } 252 253 public void setControlNum(String controlNum) { 254 this.controlNum = controlNum; 255 } 256 257 @Column(name = "flankingSequence", length = 300) 258 public String getFlankingSequence() { 259 return this.flankingSequence; 260 } 261 262 public void setFlankingSequence(String flankingSequence) { 263 this.flankingSequence = flankingSequence; 264 } 265 266 @Column(name = "foreignPublished", length = 30) 267 public String getForeignPublished() { 268 return this.foreignPublished; 269 } 270 271 public void setForeignPublished(String foreignPublished) { 272 this.foreignPublished = foreignPublished; 273 } 274 275 @Column(name = "hapMap", length = 30) 276 public String getHapMap() { 277 return this.hapMap; 278 } 279 280 public void setHapMap(String hapMap) { 281 this.hapMap = hapMap; 282 } 283 284 @Column(name = "theE", length = 30) 285 public String getTheE() { 286 return this.theE; 287 } 288 289 public void setTheE(String theE) { 290 this.theE = theE; 291 } 292 293 @Column(name = "alterSite", length = 30) 294 public String getAlterSite() { 295 return this.alterSite; 296 } 297 298 public void setAlterSite(String alterSite) { 299 this.alterSite = alterSite; 300 } 301 302 @Column(name = "alterSiteRisk", length = 30) 303 public String getAlterSiteRisk() { 304 return this.alterSiteRisk; 305 } 306 307 public void setAlterSiteRisk(String alterSiteRisk) { 308 this.alterSiteRisk = alterSiteRisk; 309 } 310 311 @Column(name = "geneCre", length = 500) 312 public String getGeneCre() { 313 return this.geneCre; 314 } 315 316 public void setGeneCre(String geneCre) { 317 this.geneCre = geneCre; 318 } 319 320 @Column(name = "createDate", length = 19) 321 public Timestamp getCreateDate() { 322 return this.createDate; 323 } 324 325 public void setCreateDate(Timestamp createDate) { 326 this.createDate = createDate; 327 } 328 329 @Column(name = "updateDate", length = 19) 330 public Timestamp getUpdateDate() { 331 return this.updateDate; 332 } 333 334 public void setUpdateDate(Timestamp updateDate) { 335 this.updateDate = updateDate; 336 } 337 338 @Column(name = "transPerson", length = 36) 339 public String getTransPerson() { 340 return this.transPerson; 341 } 342 343 public void setTransPerson(String transPerson) { 344 this.transPerson = transPerson; 345 } 346 347 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "gene") 348 public Set<Corlib> getCorlibs() { 349 return this.corlibs; 350 } 351 352 public void setCorlibs(Set<Corlib> corlibs) { 353 this.corlibs = corlibs; 354 } 355 356 }
View Code
Corlib.java的代码:
1 package com.agen.entity; 2 3 import java.sql.Timestamp; 4 import javax.persistence.Column; 5 import javax.persistence.Entity; 6 import javax.persistence.FetchType; 7 import javax.persistence.GeneratedValue; 8 import javax.persistence.Id; 9 import javax.persistence.JoinColumn; 10 import javax.persistence.ManyToOne; 11 import javax.persistence.Table; 12 import org.hibernate.annotations.GenericGenerator; 13 14 /** 15 * Corlib entity. @author MyEclipse Persistence Tools 16 */ 17 @Entity 18 @Table(name = "corlib", catalog = "biologyinfo") 19 public class Corlib implements java.io.Serializable { 20 21 // Fields 22 23 private String corlibId; 24 private Gene gene; 25 private String corlibContext; 26 private String corlibCre; 27 private Timestamp createDate; 28 private Timestamp updateDate; 29 private String transPerson; 30 31 // Constructors 32 33 /** default constructor */ 34 public Corlib() { 35 } 36 37 /** minimal constructor */ 38 public Corlib(Gene gene) { 39 this.gene = gene; 40 } 41 42 /** full constructor */ 43 public Corlib(Gene gene, String corlibContext, String corlibCre, 44 Timestamp createDate, Timestamp updateDate, String transPerson) { 45 this.gene = gene; 46 this.corlibContext = corlibContext; 47 this.corlibCre = corlibCre; 48 this.createDate = createDate; 49 this.updateDate = updateDate; 50 this.transPerson = transPerson; 51 } 52 53 // Property accessors 54 @GenericGenerator(name = "generator", strategy = "uuid.hex") 55 @Id 56 @GeneratedValue(generator = "generator") 57 @Column(name = "corlibId", unique = true, nullable = false, length = 36) 58 public String getCorlibId() { 59 return this.corlibId; 60 } 61 62 public void setCorlibId(String corlibId) { 63 this.corlibId = corlibId; 64 } 65 66 @ManyToOne(fetch = FetchType.LAZY) 67 @JoinColumn(name = "geneID", nullable = false) 68 public Gene getGene() { 69 return this.gene; 70 } 71 72 public void setGene(Gene gene) { 73 this.gene = gene; 74 } 75 76 @Column(name = "corlibContext", length = 65535) 77 public String getCorlibContext() { 78 return this.corlibContext; 79 } 80 81 public void setCorlibContext(String corlibContext) { 82 this.corlibContext = corlibContext; 83 } 84 85 @Column(name = "corlibCre", length = 500) 86 public String getCorlibCre() { 87 return this.corlibCre; 88 } 89 90 public void setCorlibCre(String corlibCre) { 91 this.corlibCre = corlibCre; 92 } 93 94 @Column(name = "createDate", length = 19) 95 public Timestamp getCreateDate() { 96 return this.createDate; 97 } 98 99 public void setCreateDate(Timestamp createDate) { 100 this.createDate = createDate; 101 } 102 103 @Column(name = "updateDate", length = 19) 104 public Timestamp getUpdateDate() { 105 return this.updateDate; 106 } 107 108 public void setUpdateDate(Timestamp updateDate) { 109 this.updateDate = updateDate; 110 } 111 112 @Column(name = "transPerson", length = 36) 113 public String getTransPerson() { 114 return this.transPerson; 115 } 116 117 public void setTransPerson(String transPerson) { 118 this.transPerson = transPerson; 119 } 120 121 }
View Code
时间: 2024-10-08 08:42:01