hibernate delete using hql

我只是一个虾纸丫 提交于 2019-12-25 04:00:11

问题


I have the following mapping in hibernate:

    <class name="com.foo.bulk_delete.test3.lim.bl.pom.impl.P4" table="P4_BDELETE">
    <list lazy="false" fetch="select" batch-size="25" name="strings" table="L_st_49eea" >
        <key>
            <column name="f_oid$1" index="I_oid$_49eea" sql-type="char(35)"/>
        </key>
        <index column="s_idx$"/>
        <element type="VarcharStringType">
            <column name="s_elem$_5eb03"  length="512"/>
        </element>
    </list>
</class>

if I want to delete all P4 elements in hql i do something similar to

delete from com.foo.bulk_delete.test3.lim.bl.pom.impl.P4 p4

but obviously I have a constraint violation exception because I need to delete the inner "L_st_49eea" table but I don't know how to do it in hql.


回答1:


You cannot do this via HQL alone.. you have to first delete the referenced entities and then delete the parent entity.
I would recommend to use delete cascade along with the foreign key constraint and then you can delete via simple HQL on parent.



来源:https://stackoverflow.com/questions/6019654/hibernate-delete-using-hql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!