我无法找出为什么hibernate会在事务提交后尝试删除集合元素。我甚至没有要求它这样做。
有什么想法吗?
技术详情发布在下面。
Hibernate方言:
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=?