我有一个非常奇怪的问题,hibernate在我不知情的情况下进行UPDATE查询。
我使用Spring + Hibernate。 Hibernate配置:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<prop key="hibernate.connection.autocommit">false</prop>
</props>
</property>
我的实体:
@Entity
@Table(name = "a")
public class A {
@Id
@GeneratedValue
private int id;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "bId")
private List<B> list;
}
-----------------------
@Entity
@Table(name = "b")
public class B{
@GeneratedValue
@Id
private int id;
@Column
private int test;
}
我在Transactional DAO中获取A的实例,并在使用此方法后
A a = ... get from DAO
List<B> listB = a.getList();
for (B o : listB){
......
}
当Java尝试获取iterator(listB.iterator())时,hibernate发出此请求:
Hibernate: update b set bId=null where bId=?