Regular |
 |
Joined: Thu Apr 21, 2005 9:05 am Posts: 50 Location: Boston, U.S
|
In a one-to-many relationship, i am trying to use all-delete-orphan cascade option.
I have no problems with insert or update in master and child table.
But when i remove some records from the collection and do a saveOrUpdate, the removed records from the collection are not
getting deleted from the database.
Delete sql is never getting triggered on the child table.
Any thoughts and suggestions are highly appreciated.
Hibernate version:
3.0
Mapping documents:
<?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 package="schema">
<class name="SlpgRoom" table="PROP_PRDT_SLPG_RM">
<id name="propertyProductId">
<column name="PROP_PRDT_ID" length="15" not-null="true"/>
</id>
<property name="defaultBaseCount">
<column name="SLPG_RM_DFLT_INV_BASE_QTY" length="9" not-null="false" />
</property>
<set name ="connectingRoomTypeProducts" cascade="all-delete-orphan" inverse="true" outer-join="false" lazy="false">
<key column ="PROP_PRDT_ID"/>
<one-to-many class="ConnectingRoom"/>
</set>
</class>
</hibernate-mapping>
==============================
<?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 package="schema">
<class name="ConnectingRoom" table="PROP_PRDT_SLPG_RM_CONNECT">
<composite-id>
<key-property name="propertyProductId" column="PROP_PRDT_ID"/>
<key-property name="connectPropertyProductId" column="CONNECT_PROP_PRDT_ID"/>
</composite-id>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
SlpgRoom slpg = new SlpgRoom();
ConnectingRoom connectRoom = new ConnectingRoom();
ConnectingRoom connectRoom1 = new ConnectingRoom();
connectRoom.setConnectPropertyProductId(new Integer("1000"));
connectRoom.setPropertyProductId(new Integer("580"));
connectRoom1.setConnectPropertyProductId(new Integer("1000"));
connectRoom1.setPropertyProductId(new Integer("582"));
Set connectingRooms = new HashSet();
connectingRooms.add(connectRoom);
//connectingRooms.add(connectRoom1);
slpg.setConnectingRoomTypeProducts(connectingRooms);
slpg.setDefaultBaseCount(new Integer("11"));
slpg.setPropertyProductId(new Integer("1000"));
tx = session.getTransaction....
session.save(slpg);
tx.commit()......
Full stack trace of any exception that occurs:
Name and version of the database you are using:
Oracle 10G
The generated SQL (show_sql=true):
Hibernate: select slpgroom_.PROP_PRDT_ID, slpgroom_.SLPG_RM_DFLT_INV_BASE_QTY as SLPG2_1_ from PROP_PRDT_SLPG_RM slpgroom_ where slpgroom_.PROP_PRDT_ID=?
Hibernate: select connecting_.PROP_PRDT_ID, connecting_.CONNECT_PROP_PRDT_ID from PROP_PRDT_SLPG_RM_CONNECT connecting_ where connecting_.PROP_PRDT_ID=? and connecting_.CONNECT_PROP_PRDT_ID=?
Debug level Hibernate log excerpt:
|
|