使用休眠获取数据时无限循环

使用休眠获取数据时无限循环

本文介绍了使用休眠获取数据时无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用 HQl 获取数据,但是在查询时发生一个奇怪的异常,请查看一次这个数据。 位于org.hibernate.loader.plan.exec.internal。 AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122)在org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)上 $ or $ $ $ $在org.hibernate.loader.entity。 plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107)在org.hibernate.event.internal.DefaultLoadEventListener。 loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478)在org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)在org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278)在org.hibernate作为.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121)在org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)在org.hibernate.internal.SessionImpl .fireLoad(SessionImpl.java:1239)在org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)在org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680 )在org.hibernate.type.EntityType.resolve(EntityType.java:462)在org.hibernate.type.EntityType.resolve(EntityType.java:455) at org。 hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(En tityReferenceInitializerImpl.java:142)位于org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143)位于org.hibernate.loader.plan.exec。 process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94)在org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails $ EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241)。在组织。 hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167 )在org.hibernate.persister.entity.AbstractEntityPersister.lo广告(AbstractEntityPersister.java:4107)在org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508)在org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener。 org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)在org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239)在org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)在org.hibernate.type.EntityType .resolveIdentifier(EntityType.java:680)在org.hibernate.type.EntityType.resolve(Entit at org.hibernate.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey( AbstractRowReader.java:143)在org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94)在org.hibernate.loader.plan.exec。 internal.EntityLoadQueryDetails $ EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241)在org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122)。在组织。 hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122)位于org.hibernate.loader.plan.exec.internal。 AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister。负载(AbstractEntityPersister.java:4107)。在org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508)。在org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener。 org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)在org.hibernat e.internal.SessionImpl.fireLoad(SessionImpl.java:1239)位于org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)位于org.hibernate.type.EntityType.resolveIdentifier( EntityType.java:680)在org.hibernate.type.EntityType.resolve(EntityType.java:462)在org.hibernate.type.EntityType.resolve(EntityType.java:455)$ b在org.hibernate.type.ComponentType.resolve(ComponentType.java:688) $ b在org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142)$ b在org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143) $ b在org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow( AbstractRowReader.java:94)在org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails $ EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241)在org.hibernate.loader.plan.e xec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org。 hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)在org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167)。在org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107)处org.hibernate作为org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508)。 event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478)在org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)。在org.hibernate.event.internal。 DefaultLoadEventListener.proxyOrLoad(德faultLoadEventListener.java:278)在org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121)在org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java: 89)美元,org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239 b $ b)在org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)。在组织.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680)在org.hibernate.type.EntityType.resolve(EntityType.java:462)在org.hibernate.type.EntityType.resolve (EntityType.java:455) org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey (EntityReferenceInitializerImpl.java:142) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143) at org。 hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94) at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails $ EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241 )在org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults (ResultSetProcessorImpl.java:122)在org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad (AbstractLoadPlanBasedLoader.java:122)$ or $ $ b $ org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) .load(AbstractLoadPlanBasedEntityLoader.java:167)在org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107)在org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener .java:508)$ or $ $ b $ org.hibe rnate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478)在org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)在org.hibernate.event。 internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278)处org.hibernate.event.internal.DefaultLoadEventListener org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121)。 onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)在org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680) 在org.hibernate.type.EntityType.resolve(EntityType.java:462)在org.hibernate作为.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at or g.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142)在org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java :143) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94) at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails $ EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader .plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122)$ or $ $ b $ org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org .hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanB org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:在org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478 508))。在org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)$ b在org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) $ b在org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121)。在组织.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl .internalLoad(SessionImpl.java:1122)在org.hibernate.type.EntityTyp e.resolveIdentifier(EntityType.java:680)在org.hibernate.type.EntityType.resolve(EntityType.java:462)在org.hibernate.type.EntityType.resolve(EntityType.java: 455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) 请看看我的查询 currentSession = sessionFactory.getCurrentSession(); Query query = currentSession.createQuery(from AssocFeeStudent asf where asf.studentDetails.studentAdmissionId =:studentAdmissionId); query.setParameter(studentAdmissionId,id); query.getResultList(); 请查看我的实体类 @Entity @Table(name =assoc_fee_student,catalog =campus_guru_01)公共类AssocFeeStudent实现java.io.Serializable { 私人FeeCategory feeCategory; private StudentDetails studentDetails; Public AssocFeeStudent(){} Public AssocFeeStudent(FeeCategory feeCategory,StudentDetails studentDetails){ this.feeCategory = feeCategory; this.studentDetails = studentDetails; } @EmbeddedId @AttributeOverrides({ @AttributeOverride(名称= feeCatId,柱= @Column(名称= fee_cat_id ,nullable = false)), @AttributeOverride(name =studentId,column = @Column(name =student_id,nullable = false))}) @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name =fee_cat_id,nullable = false)公共FeeCategory getFeeCategory(){ return this.feeCategory; } public void setFeeCategory(FeeCategory feeCategory){ this.feeCategory = feeCategory; } @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name =student_id,nullable = false) public StudentDetails getStudentDetails(){返回this.studentDetails; } public void setStudentDetails(StudentDetails studentDetails){ this.studentDetails = studentDetails; } } 以及相关实体 p> FeeCategory @Entity @Table(name =fee_category,catalog =campus_guru_01) 公共类FeeCategory implements java.io.Serializable { $ b $ private private整数feeCatId; private String feeCatName; private int parentId; private Set< AssocFeeTerms> assocFeeTermses = new HashSet< AssocFeeTerms>(0); 私人套餐< FeeClassMapping> feeClassMappings = new HashSet< FeeClassMapping>(0); 私人套餐< FeeTransactions> feeTransactionses = new HashSet< FeeTransactions>(0); 私人设置< AssocFeeStudent> assocFeeStudents = new HashSet< AssocFeeStudent>(0); $ b $公共FeeCategory(){} 公共FeeCategory(int parentId){ this.parentId = parentId; } 公共FeeCategory(字符串feeCatName,INT parentId的,组< AssocFeeTerms> assocFeeTermses,组< FeeClassMapping> feeClassMappings,组< FeeTransactions> feeTransactionses,组< AssocFeeStudent> assocFeeStudents){ this.feeCatName = feeCatName; this.parentId = parentId; this.assocFeeTermses = assocFeeTermses; this.feeClassMappings = feeClassMappings; this.feeTransactionses = feeTransactionses; this.assocFeeStudents = assocFeeStudents; @Id @GeneratedValue(strategy = IDENTITY) @Column(name =fee_cat_id,unique = true,nullable = false ) public Integer getFeeCatId(){ return this.feeCatId; } public void setFeeCatId(Integer feeCatId){ this.feeCatId = feeCatId; @Column(name =fee_cat_name) public String getFeeCatName(){ return this.feeCatName; } public void setFeeCatName(String feeCatName){ this.feeCatName = feeCatName; @Column(name =parent_id,nullable = false) public int getParentId(){ return this.parentId; } public void setParentId(int parentId){ this.parentId = parentId; } @OneToMany(fetch = FetchType.EAGER,mappedBy =feeCategory) public Set< AssocFeeStudent> getAssocFeeStudents(){返回this.assocFeeStudents; } 公共无效setAssocFeeStudents(设置< AssocFeeStudent> assocFeeStudents){ this.assocFeeStudents = assocFeeStudents; } } StudentDetails @Entity @Table(name =student_details,catalog =campus_guru_01) public class StudentDetails实现java.io.Serializable { private Integer studentAdmissionId; private String isPrimaryyn; private String adsmissionNum; 私人字符串名字; 私人字符串姓氏; 私人设置< AssocFeeStudent> assocFeeStudents = new HashSet< AssocFeeStudent>(0); @JsonIgnore @OneToMany(fetch = FetchType.EAGER,mappedBy =studentDetails) public Set< AssocFeeStudent> getAssocFeeStudents(){返回this.assocFeeStudents; } 公共无效setAssocFeeStudents(设置< AssocFeeStudent> assocFeeStudents){ this.assocFeeStudents = assocFeeStudents; } } 跟踪它。这是怎么回事? 可以任何一个解决吗? 谢谢! 解决方案我希望您有合适的理由在您的查询中提到这种关系。 无论如何,尝试延迟获取集合,即而不是 @OneToMany(fetch = FetchType.EAGER,mappedBy =studentDetails)和 @OneToMany(fetch = FetchType.EAGER,mappedBy =feeCategory) 使用 @OneToMany(fetch = FetchType.LAZY,mappedBy =studentDetails)和 @OneToMany(fetch = FetchType.LAZY,mappedBy =feeCategory) 并且使用@JsonBackReference来提示hibernate,反向引用映射只是一个镜像而不是新映射。 PS我强烈建议你应该重新访问实体关系 i am fetching data using HQl but one strange exception occurring while querying please look at this onceat org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680) at org.hibernate.type.EntityType.resolve(EntityType.java:462) at org.hibernate.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94) at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680) at org.hibernate.type.EntityType.resolve(EntityType.java:462) at org.hibernate.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94) at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680) at org.hibernate.type.EntityType.resolve(EntityType.java:462) at org.hibernate.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94) at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680) at org.hibernate.type.EntityType.resolve(EntityType.java:462) at org.hibernate.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94) at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680) at org.hibernate.type.EntityType.resolve(EntityType.java:462) at org.hibernate.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688) at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.resolveEntityKey(EntityReferenceInitializerImpl.java:142) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.resolveEntityKey(AbstractRowReader.java:143) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:94) at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:241) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4107) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:680) at org.hibernate.type.EntityType.resolve(EntityType.java:462) at org.hibernate.type.EntityType.resolve(EntityType.java:455) at org.hibernate.type.ComponentType.resolve(ComponentType.java:688)the above Exception getting as infinite .please look at my query currentSession = sessionFactory.getCurrentSession(); Query query = currentSession.createQuery("from AssocFeeStudent asf where asf.studentDetails.studentAdmissionId= :studentAdmissionId"); query.setParameter("studentAdmissionId", id); query.getResultList();please have a look on my entity classesAssocFeeStudent @Entity @Table(name = "assoc_fee_student", catalog = "campus_guru_01") public class AssocFeeStudent implements java.io.Serializable { private FeeCategory feeCategory; private StudentDetails studentDetails; public AssocFeeStudent() { } public AssocFeeStudent( FeeCategory feeCategory, StudentDetails studentDetails) { this.feeCategory = feeCategory; this.studentDetails = studentDetails; } @EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "feeCatId", column = @Column(name = "fee_cat_id", nullable = false)), @AttributeOverride(name = "studentId", column = @Column(name = "student_id", nullable = false)) }) @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "fee_cat_id", nullable = false) public FeeCategory getFeeCategory() { return this.feeCategory; } public void setFeeCategory(FeeCategory feeCategory) { this.feeCategory = feeCategory; } @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "student_id", nullable = false) public StudentDetails getStudentDetails() { return this.studentDetails; } public void setStudentDetails(StudentDetails studentDetails) { this.studentDetails = studentDetails; } }and the dependent entities areFeeCategory @Entity@Table(name = "fee_category", catalog = "campus_guru_01")public class FeeCategory implements java.io.Serializable { private Integer feeCatId; private String feeCatName; private int parentId; private Set<AssocFeeTerms> assocFeeTermses = new HashSet<AssocFeeTerms>(0); private Set<FeeClassMapping> feeClassMappings = new HashSet<FeeClassMapping>(0); private Set<FeeTransactions> feeTransactionses = new HashSet<FeeTransactions>(0); private Set<AssocFeeStudent> assocFeeStudents = new HashSet<AssocFeeStudent>(0); public FeeCategory() { } public FeeCategory(int parentId) { this.parentId = parentId; } public FeeCategory(String feeCatName, int parentId, Set<AssocFeeTerms> assocFeeTermses, Set<FeeClassMapping> feeClassMappings, Set<FeeTransactions> feeTransactionses, Set<AssocFeeStudent> assocFeeStudents) { this.feeCatName = feeCatName; this.parentId = parentId; this.assocFeeTermses = assocFeeTermses; this.feeClassMappings = feeClassMappings; this.feeTransactionses = feeTransactionses; this.assocFeeStudents = assocFeeStudents; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "fee_cat_id", unique = true, nullable = false) public Integer getFeeCatId() { return this.feeCatId; } public void setFeeCatId(Integer feeCatId) { this.feeCatId = feeCatId; } @Column(name = "fee_cat_name") public String getFeeCatName() { return this.feeCatName; } public void setFeeCatName(String feeCatName) { this.feeCatName = feeCatName; } @Column(name = "parent_id", nullable = false) public int getParentId() { return this.parentId; } public void setParentId(int parentId) { this.parentId = parentId; }@OneToMany(fetch = FetchType.EAGER, mappedBy = "feeCategory") public Set<AssocFeeStudent> getAssocFeeStudents() { return this.assocFeeStudents; } public void setAssocFeeStudents(Set<AssocFeeStudent> assocFeeStudents) { this.assocFeeStudents = assocFeeStudents; }}StudentDetails @Entity@Table(name = "student_details", catalog = "campus_guru_01")public class StudentDetails implements java.io.Serializable { private Integer studentAdmissionId; private String isPrimaryyn; private String adsmissionNum; private String firstname; private String lastname;private Set<AssocFeeStudent> assocFeeStudents = new HashSet<AssocFeeStudent>(0);@JsonIgnore @OneToMany(fetch = FetchType.EAGER, mappedBy = "studentDetails") public Set<AssocFeeStudent> getAssocFeeStudents() { return this.assocFeeStudents; } public void setAssocFeeStudents(Set<AssocFeeStudent> assocFeeStudents) { this.assocFeeStudents = assocFeeStudents; }}its strange to me not able to trace it . whats happening in this.can any one solve it ?thank you!. 解决方案 I hope you have proper reasons to have the kind of relationship mentioned in your query.Anyway try fetching collection lazily i.e.instead of@OneToMany(fetch = FetchType.EAGER, mappedBy = "studentDetails") and @OneToMany(fetch = FetchType.EAGER, mappedBy = "feeCategory")use@OneToMany(fetch = FetchType.LAZY, mappedBy = "studentDetails") and @OneToMany(fetch = FetchType.LAZY, mappedBy = "feeCategory")And use @JsonBackReference to hint hibernate that back reference mapping is just a mirror image instead of new mappingP.S. I strongly suggest you should revisit entity relationships 这篇关于使用休眠获取数据时无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 13:41