-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate setting null in child record's FK before deleting
PostPosted: Mon Sep 04, 2006 11:29 am 
Newbie

Joined: Thu May 18, 2006 1:46 pm
Posts: 10
Hibernate version: 3.1.2

Mapping documents:
[code]
<set
name="participantes"
table="USUARIO"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
order-by="nome"
where="TIPO_USUARIO = 'P'"
>

<key
column="ID_EVENTO"
>
</key>

<one-to-many
class="*.*.*.*.Participante"
/>
<many-to-one
name="moderador"
class="*.*.*.*.Moderador"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="ID_MODERADOR"
/>
[code]


Hello there! I have the above mapping in one of my classes. Both Participante and Moderador descend from the same super class Usuario (using a table per class hierarchy model).

I'm having a problem when deleteing the parent entity (Evento). It's updating the child (couldn't figure if the ones from the Set or from the many-to-one) and setting their FK to null. This is causing an constraint exception on my database. It seems that Hibernate sets the FK to null, then deletes the parent, then it deletes everyone from Usuario table where ID_EVENTO = null. How do I avoid this situation?

Regards

Vinicius


Top
 Profile  
 
 Post subject: Don't cascade
PostPosted: Tue Sep 05, 2006 9:46 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
You specify cascade=all, so Hibernate tries to delete the entities on the many site.
Try without 'all'. The delete will then fail (foreign-key violation or something like that from the db).
Or maybe a clear() on the collection property will work

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.