These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Child record excluding Parent using SaveOrUpdateCopy
PostPosted: Fri Oct 06, 2006 1:27 pm 
Newbie

Joined: Fri Oct 06, 2006 1:06 pm
Posts: 2
Here are my mapping files:


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SGP.Business.Financeiro.MoedasBsn,SGP.Business" table="MOEDAS" dynamic-update="true">

<id name="codigo" column="CODIGO" type="Int32" unsaved-value="0">
<generator class="increment"/> <!-- (increment, identity, sequence, assigned, etc.) -->
</id>
<property column="DESCRICAO" type="String" name="descricao" not-null="true" length="50" />
<property column="SIMBOLO" type="String" name="simbolo" not-null="true" length="3" />

<bag name="valoresMoedas" inverse="true" cascade="all-delete-orphan">
<key column="CODIGOMOEDA" />
<one-to-many class="SGP.Business.Financeiro.ValoresMoedasBsn,SGP.Business" />
</bag>

</class>
</hibernate-mapping>


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SGP.Business.Financeiro.ValoresMoedasBsn,SGP.Business" table="VALORESMOEDAS">

<id name="codigo" column="CODIGO" type="Int32" unsaved-value="0">
<generator class="increment"/> <!-- (increment, identity, sequence, assigned, etc.) -->
</id>

<many-to-one name="moeda" column="CODIGOMOEDA" class="SGP.Business.Financeiro.MoedasBsn,SGP.Business" cascade = "all" />

<property column="DATAREFERENCIA" type="DateTime" name="dataReferencia" not-null="true" />
<property column="VALOR" type="Int32" name="valor" not-null="true" />

</class>
</hibernate-mapping>


The problem is that when I try to update a parent (Moeda), by deleting one of its soon (ValoresMoedas) and then calling saveOrUpdateCopy(Moeda), the parent(Moeda) is also deleted. I load the object Moeda in one Session and persist it in another one, that is why I use saveOrUpdateCopy(object).

Does anyone have a clue?

Thanks!


Top
 Profile  
 
 Post subject: Re: Child record excluding Parent using SaveOrUpdateCopy
PostPosted: Fri Oct 06, 2006 1:47 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
Bruno Tarcha wrote:
<many-to-one name="moeda" column="CODIGOMOEDA" class="SGP.Business.Financeiro.MoedasBsn,SGP.Business" cascade = "all" />


I think the problem is the cascade = "all" here. Depending on the way you want to delete ValoresMoedasBsn instances you'd better use cascade="none" or "save-update".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 2:05 pm 
Newbie

Joined: Fri Oct 06, 2006 1:06 pm
Posts: 2
Hey!

I was making so many changes to test it that I even forgot that cascade there! Lol

I just removed the property and it worked perfectly.

Thank you very much!!!!! I was trying to make it work for a long time!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.