Posted on 2005-09-01 23:59
飞翔 阅读(273)
评论(0) 编辑 收藏 所属分类:
Java
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=info
inverse="false" 则本类为主控方,hibernate会自动查找关联的对象(即使不给完全的对象)
inverse = "true" 为被控方
cascade = "delete"或其他 必须是个完整的对象hibernate才会去删除关联的对象,否则不予删除
<set name="members" table="USERGROUP" lazy="true"
inverse="false" cascade="delete" sort="unsorted">
<key column="groupid"></key>
<many-to-many class="Sysuser" column="userid">
</many-to-many>
</set>
现对inverse 和cascade 属性在不同条件下测试,结果如下:
( 全为完整对象,否则cascade delete 不会级联删除,除非inverse= false 而不出错)
inverse cascade result
-------------------------------------
true delete delete sysgroup,sysuser
true none delete sysgroup
false delete delete sysgroup,sysuser,user-group
false none delete sysgroup,user-group
<set name="permissions" table="group_permissions" lazy="true"
inverse="true" cascade="delete" sort="unsorted">
<key column="GROUPID"></key>
<one-to-many class="GroupPermissions" />
</set>
(完整的对象)
one-to-many :
inverse cascade result
------------------------------------
true delete 删除 sysgroup,grouppermissions
true none 只删除 sysgroup
false 两种情况 出错,不能更新grouppermissions=null