-->
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: Correct usage of mapping "cascade" tags
PostPosted: Tue Apr 12, 2005 6:12 pm 
Newbie

Joined: Tue Apr 05, 2005 11:31 pm
Posts: 3
Hi,
I have been having some dificulties on how to configure and use the cascade tags when mapping one-to-many relationships.
In the case I am working on right now, I have one entity called LoteFinanceiro which has 2 one-to-many relationships, one with Cheque and another one with Dinheiro. You will be able to see the code in the mappings below.
I have been trying to use cascade="all", but when I delete in memory either one or several elements from one of these relationships, and try to update the main entity "LoteFinanceiro", it doesn't return any error, and does not make any changes in the database either. It is importante to remind that I am loading everything in one session and doing the update in another session.
So, I wonder if I am using the right tags for cascade.
Here follows what I really want to do:

1) When I delete de Main Entity "LoteFinanceiro", I want all the child elements from those one-to-many relations to be also deleted.
2) When I delete any child element from the relationships and try to update the main Entity, it has to be also deleted from the database.

Does anyone know how to do this?

Hibernate version:
Hibernate 3.0

Mapping documents:
LoteFinanceiro
<hibernate-mapping>
<class name="com.compunet.cnetfinanceiro.LoteFinanceiro" table="F_LoteFinanceiro" lazy="false">
<id name="numeroLote" column="ID_NumeroLote" type="long" unsaved-value="-1">
<generator class="identity">
</generator>
</id>
<property name="dataEnvio" column="DataEnvio" type="date"/>
<property name="valorTotal" column="valorTotal" type="double"/>
<property name="portador" column="Portador" type="string"/>
<property name="destinatario" column="Destinatario" type="text"/>
<property name="observacao" column="Observacao" type="text"/>
<property name="usuario" column="Usuario" type="string"/>


<set name="cheques"
lazy="false"
inverse="true"
cascade="all"
table="F_Cheque">

<key column="ID_NumeroLote"></key>
<one-to-many class="com.compunet.cnetfinanceiro.Cheque"/>
</set>

<set name="dinheiros"
lazy="false"
inverse="true"
cascade="all"
table="F_Dinheiro">

<key column="ID_NumeroLote" ></key>
<one-to-many class="com.compunet.cnetfinanceiro.Dinheiro"/>
</set>


</class>
</hibernate-mapping>

Dinheiro

<hibernate-mapping>
<class name="com.compunet.cnetfinanceiro.Dinheiro" table="F_Dinheiro" lazy="false">
<id name="id" column="ID_Dinheiro" type="long" unsaved-value="-1">
<generator class="identity"/>
</id>
<property name="valor" column="Valor" type="double"/>
<property name="moeda" column="Moeda" type="string"/>
<property name="observacao" column="Observacao" type="text"/>

<many-to-one
name="loteFinanceiro"
class="com.compunet.cnetfinanceiro.LoteFinanceiro"
column="ID_NumeroLote"
not-null="true"
cascade="all"
outer-join="auto"
/>

</class>
</hibernate-mapping>

Cheque

<hibernate-mapping>
<class name="com.compunet.cnetfinanceiro.Cheque" table="F_Cheque" lazy="false">
<id name="id" column="ID_Cheque" type="long" unsaved-value="-1">
<generator class="identity"/>
</id>
<property name="valor" column="Valor" type="double"/>
<property name="moeda" column="Moeda" type="string"/>
<property name="observacao" column="Observacao" type="text"/>
<property name="numero" column="Numero" type="string"/>
<property name="contaCorrente" column="ContaCorrente" type="string"/>
<property name="codigoBanco" column="CodigoBanco" type="string"/>
<property name="codigoAgencia" column="CodigoAgencia" type="string"/>
<property name="codigoCliente" column="CodigoCliente" type="string"/>
<property name="dataVencimento" column="DataVencimento" type="date"/>
<many-to-one
name="loteFinanceiro"
class="com.compunet.cnetfinanceiro.LoteFinanceiro"
column="ID_NumeroLote"
not-null="true"
cascade="all"
outer-join="auto"
/>
</class>
</hibernate-mapping>

Name and version of the database you are using:
Sql Server 2000 with TDS Driver


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 7:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
See http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html

use cascade="all-delete-orphan"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 9:19 am 
Newbie

Joined: Tue Apr 05, 2005 11:31 pm
Posts: 3
david wrote:


Hello David,
I had already tried to use this tag, but it is not working quite as how I described. It is returning all kind of key errors when I try to update the main Entity LoteFinanceiro.
To achieve that behavior that I described are the mappings the child entities "Dinheiro" and "Cheque" right? It seems like every little change I make in the mappings I get different behavior and errors, and I have not reached exactaly what I want......

Could you could you give some more help one this David?
Thanks a lot in advance!


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.