• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cascade Issue

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you try, cascade="all,delete-orphan"?
 
saumil baxi
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cascade="all,delete-orphan" does not work with <many-to-one > ...
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
a wee bit from the empire
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic