File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Cascade Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Cascade Issue" Watch "Cascade Issue" New topic

Cascade Issue

saumil baxi
Ranch Hand

Joined: Apr 18, 2008
Posts: 58
I have one class (Class1 )which have reference to another class (Class2)....
so whenever i do saveorupdate(Class1). it updates it and also enter the value in table of class2. but the old value still remains in class2...
Below is my hbm.xml file..

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"" >

<hibernate-mapping package="com.cobra.configuration.manager.hibernate">
<meta attribute="sync-DAO">false</meta>

<composite-id name="CompositeProperty" class="CompositeProperty">
<key-property name="key" type="string" column="KEY"/>
<key-property name="context" type="string" column="CONTEXT"/>

<many-to-one name="value" class="IfcConfigurationValue" column="value"
cascade="all" lazy="false" unique="true"/>

name="IfcConfigurationValue" abstract="true"
<generator class="uuid.hex"/>

<union-subclass name="ListValues" table="List_Values">
<list name="IfcConfigurationValue" cascade="all" table="List_Values_Details" lazy="false">
<key column="PARENTID"/>
<index column="ID"/>
<many-to-many class="IfcConfigurationValue" column="IntfConfigurationValue"/>


<union-subclass name="StringValues" table="String_Values">

<union-subclass name="MapValues" table="Map_Values">
<map name="IfcConfigurationValue" table="Map_Values_Details" cascade="all" lazy="false" >
<key column="PARENTID"/>
<index column="ID" type="string"/>
<many-to-many class="IfcConfigurationValue" column="IntfConfigurationValue"/>



<query name="app.cobra.get.key.value">from ConfigProperty where Key = ? </query>


Please Help me out..

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

it updates it

Which it is it?

So the database gets updated properly, but the local bean Class 2 is not updated? Or class2 is updated, but the database is not updated?

Perhaps you're actually creating a new class 2, as opposed to actually updating a new instance. As such, the new class2 is updated, but the program holds a reference to the old value?

If this is the case, you may be having a 'pass by reference' type of issue. Check to see if you're using the new keyword anywhere with this second instance. I bet that's it.

-Cameron McKenzie
saumil baxi
Ranch Hand

Joined: Apr 18, 2008
Posts: 58
Sorry for creating confusion...

As i m new to hibernate i dont know how to talk in terms of class in hibernate.. so will explain again..

i have 2 tables
table config having columns key,context,value

here value
<many-to-one name="value" class="IfcConfigurationValue" column="value"
cascade="all" lazy="false" />

Table ifcConfigurationValue having columns ID,value

where ID is mapped to value..

so when i say saveor update(ConfigProperty) i.e the first Class..

it updates the reference in value column but it doesnot delete the reference in ifcConfigurationValue table..

Please let me know if you want any clarification

Hongli Li
Ranch Hand

Joined: Oct 29, 2006
Posts: 124
did you try, cascade="all,delete-orphan"?

Do you know why this cup is useful? Because it is empty.
saumil baxi
Ranch Hand

Joined: Apr 18, 2008
Posts: 58
cascade="all,delete-orphan" does not work with <many-to-one > ...
Saravanan Thoppae

Joined: Jun 30, 2007
Posts: 13
cascade option works for many-to-one mapping. Please provide a clear explanation of your parent object, associated child object and what is the problem when you save or update your parent object. You might have explained but it will be nice if you explain clearly.
I agree. Here's the link:
subject: Cascade Issue
It's not a secret anymore!