我不知道为什么冬眠试图在事务提交后删除集合元素。我什至不要求它这样做。
有任何想法吗?
技术细节在下面发布。
休眠方言:
org.hibernate.dialect.SQLServerDialect
实体类:
@Entity
@Table(name = "View_m_activity", schema = "model")
public class SourceActivity {
private Set<SourceActivityAttrOut> outputAttributes;
private Long ID;
@Id
public Long getID() {
return ID;
}
public void setID(Long ID) {
this.ID = ID;
}
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "View_m_activity_attr_out", schema = "model", joinColumns = @JoinColumn(name = "activity_id"))
public Set<SourceActivityAttrOut> getOutputAttributes() {
return outputAttributes;
}
public void setOutputAttributes(Set<SourceActivityAttrOut> outputAttributes) {
this.outputAttributes = outputAttributes;
}
}
集合元素实体类:
@Embeddable
public class SourceActivityAttrOut {
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
执行代码:
@Transactional
public void readSource(SourcePool sourcePool) {
sessionFactory.getCurrentSession().createQuery("from SourceActivity", SourceActivity.class).list();
}
日志信息:
Hibernate:
select
sourceacti0_.ID as ID1_0_
from
model.View_m_activity sourceacti0_
Hibernate:
select
outputattr0_.activity_id as activity1_1_0_,
outputattr0_.code as code2_1_0_
from
model.View_m_activity_attr_out outputattr0_
where
outputattr0_.activity_id=?
Hibernate:
select
outputattr0_.activity_id as activity1_1_0_,
outputattr0_.code as code2_1_0_
from
model.View_m_activity_attr_out outputattr0_
where
outputattr0_.activity_id=?
Hibernate:
select
outputattr0_.activity_id as activity1_1_0_,
outputattr0_.code as code2_1_0_
from
model.View_m_activity_attr_out outputattr0_
where
outputattr0_.activity_id=?
Hibernate:
select
outputattr0_.activity_id as activity1_1_0_,
outputattr0_.code as code2_1_0_
from
model.View_m_activity_attr_out outputattr0_
where
outputattr0_.activity_id=?
Hibernate:
delete
from
model.View_m_activity_attr_out
where
activity_id=?
最佳答案
问题原因在here中描述
很快,为了解决该问题,我不得不重写哈希码和SourceActivityAttrOut的等价物。