Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top