Hibernate using hql

I have the following sleep display:

    <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 drop the internal table "L_st_49eea" but i dont know how to do it in hql.

0


source to share


1 answer


You cannot do this with HQL alone. you must first remove the referenced objects and then remove the parent object.
I would recommend using a delete cascade along with a foreign key constraint and then you can delete with a simple HQL parent.



+1


source







All Articles