我正在使用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();
请看一下我的实体类
副学费学生
@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;
}
}
并且从属实体是
费用类别
@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;
}
}
对我来说奇怪的是无法追踪它。这是怎么回事。
有人可以解决吗?
谢谢!。
最佳答案
我希望您有适当的理由拥有查询中提到的那种关系。
无论如何,请尝试延迟获取集合,即
代替@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暗示休眠,反向引用映射只是一个镜像,而不是新的映射
附言我强烈建议您重新访问实体关系