aspose file tools*
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
Author

Cascade Issue

saumil baxi
Ranch Hand

Joined: Apr 18, 2008
Posts: 58
Hi,
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"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.cobra.configuration.manager.hibernate">
<class
name="ConfigProperty"
table="CONFIG_PROPERTY"
>
<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"/>
</composite-id>

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


</class>
<class
name="IfcConfigurationValue" abstract="true"
>
<id
name="id"
type="string"
column="ID"
>
<generator class="uuid.hex"/>
</id>

<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"/>
</list>

</union-subclass>

<union-subclass name="StringValues" table="String_Values">
<property
name="values"
column="STRINGVALUES"
type="string"
not-null="false"
length="50"
/>
</union-subclass>

<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"/>
</map>

</union-subclass>

</class>


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

</hibernate-mapping>


Please Help me out..

Thanks,
Saumil
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Thanks,
Saumil
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
Greenhorn

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Cascade Issue