I have a problem deleting a child element from a collection.
I have cascade="all" and the SQL is correct but the entry is not deleted from the database. I've read up on similar problems and I don't seem to have anything wrong.
The CertType can contain 0-n StatementTitles but the StatementTitle can exist on its own. Therefore I only want to delete the reference to the StatementTitle i.e the entry in the DPCS_TYPE_STMT_TITLE_LINKS table and not the StatementTitle in the DPCS_STATEMENT_TITLE table.
The application has no problem adding and saving any child StatementTitles to the colleciton in the parent (CertType) class.
I've been pulling my hair out for 2 days on this and need some help.
thanks in advance
Hibernate version:
3.1
Mapping documents:
extract from CertType.hbm.xml that maps the collection
Code:
<set name="certStatementTitles"
table="DPCS_TYPE_STMT_TITLE_LINKS"
cascade="all"
order-by="STATEMENT_TITLE_ID asc"
lazy="false">
<key column="CERT_TYPE_ID"/>
<many-to-many column="STATEMENT_TITLE_ID"
class="cert.StatementTitle"/>
</set>
StatementTitle.hbm.xmlCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="cert.StatementTitle" lazy="false" table="DPCS_STATEMENT_TITLE">
<id name="statementTitleId" column="STATEMENT_TITLE_ID" unsaved-value="0" type="long">
<generator class="sequence">
<param name="sequence">STATEMENT_TITLE_ID_SEQ</param>
</generator>
</id>
<property name="title" column="STATEMENT_TITLE" type="string"/>
<property name="selectable" column="SELECTABLE" type="string"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.getSession();
CertType certType = (CertType)session.get(CertType.class, certTypeId);
StatementTitle statementTitle = (StatementTitle)session.get(StatementTitle.class, statementTitleId);
certType.getCertStatementTitles().remove(statementTitle);
session.flush();
Name and version of the database you are using: Oracle 10i
The generated SQL (show_sql=true):
delete
from
dpcs.DPCS_TYPE_STMT_TITLE_LINKS
where
CERT_TYPE_ID=?
and STATEMENT_TITLE_ID=?
Problems with Session and transaction handling?
I'm using the
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.OC4JTransactionManagerLookup</property>
Read this:
http://hibernate.org/42.html