Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cascade Issue

 
saumil baxi
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you try, cascade="all,delete-orphan"?
 
saumil baxi
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cascade="all,delete-orphan" does not work with <many-to-one > ...
 
Saravanan Thoppae
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic