I have to delete an object that has a
many-to-one association in his primary key using the
HQL delete request (for performance reason).
The associated object has the key defined in a
composite-id (with id there is no error).
The HQL request is :
this.getSession().createQuery("delete Label label where label.numseq = '01' and label.codlan = '01'" and label.mytad.argtbl = 'BE' and label.mytad.numbtl = '054' ").executeUpdate();
I can see in the log file the generated SQL :
delete from JPRG.LABEL,
MYTAD mytad1_ where NUMSEQ='01' and CODLAN='01' and ARGTBL='BE' and NUMBTL='054'
I don't understand why hibernate adds MYTAD mytad1_ in the generated SQL. This causes the following error :
SQL command not properly ended.
Here are the mapping files :
Code:
<hibernate-mapping package="com.cwsoft.businessobject">
<class name="Label" table="LABEL" schema="JPRG">
<composite-id>
<key-many-to-one name="mytad">
<column name="NUMBTL"/>
<column name="ARGTBL"/>
</key-many-to-one>
<key-property name="numseq" type="string">
<column name="NUMSEQ"/>
</key-property>
<key-property name="codlan" type="string">
<column name="CODLAN"/>
</key-property>
</composite-id>
<property name="labele" column="LABELE" type="string" not-null="true" />
</class>
</hibernate-mapping>
The associated class is defined with a composite-id :
Code:
<hibernate-mapping package="com.cwsoft.businessobject">
<class name="Mytad" table="MYTAD">
<composite-id>
<key-property name="numbtl" type="string">
<column name="NUMBTL"/>
</key-property>
<key-property name="argtbl" type="string">
<column name="ARGTBL"/>
</key-property>
</composite-id>
<property name="thdesc" type="string" column="THDESC"/>
</class>
</hibernate-mapping>