我使用HQl
获取数据,但在查询时发生了一个奇怪的异常,请查看一次
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)
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)
以上异常变得无限。
请查看我的查询
currentSession = sessionFactory.getCurrentSession();
Query query = currentSession.createQuery("from AssocFeeStudent asf where asf.studentDetails.studentAdmissionId= :studentAdmissionId");
query.setParameter("studentAdmissionId", id);
query.getResultList();
请查看我的实体类
AssocFeeStudent
@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;
}
}
和依赖实体
FeeCategory
@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;
}
}
学生详细信息
@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;
}
}
对我来说很难跟踪它。发生了什么事。
任何人都可以解决它吗?
谢谢!答案 0 :(得分:1)
我希望你有充分的理由在你的查询中提到这种关系。
无论如何尝试懒惰地取出收藏品,即
代替
@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,后引用映射只是一个镜像而不是新的映射
P.S。我强烈建议你重新审视实体关系