-->
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: OneToMany : deleting object from DB when removed from Set
PostPosted: Thu Sep 28, 2006 10:47 pm 
Newbie

Joined: Fri Jul 14, 2006 10:52 am
Posts: 16
I declared a OneToMany with corresponding ManyToOne as

@OneToMany( cascade = {CascadeType.ALL}, mappedBy="incident")
private Set<CustomIncidentAttribute> cias = new HashSet<CustomIncidentAttribute>(0);

and

@ManyToOne @JoinColumn(name = "INCIDENT_FK")
private Incident incident;

When I removed an entity from the Set, I only noticed that the incident field of the other end was nullified, but the object was not removed.

Then I read that if you want the OneToMany to be the owner, you should define it as:

@OneToMany( cascade = {CascadeType.ALL)
@JoinColumn(name = "INCIDENT_FK")
private Set<CustomIncidentAttribute> cias = new HashSet<CustomIncidentAttribute>(0);

and

@ManyToOne @JoinColumn(name = "INCIDENT_FK", insertable=false, updatable=false)
private Incident incident;

I.e you remove the mappedBy and add the joinColumn.
However I still see the same behaviour that when I remove from a set the other end's incident is just nullified, but the object stays in the DB.

Can you remove an object from a set and actually remove it from the DB also?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 3:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use DELETE_ORPHAN, check the doc for the usage

_________________
Emmanuel


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.