-->
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: Newbie question concerning oneToMany
PostPosted: Tue Feb 14, 2006 3:02 pm 
Newbie

Joined: Mon Mar 21, 2005 9:41 am
Posts: 12
Hello to everybody,

i have a problem modelling a bidirectional oneToMany relation where the owning side deletes the owned objects. Here's the code:

owning side:
Code:
@OneToMany(fetch= FetchType.EAGER, cascade={CascadeType.ALL})
   @JoinColumn(name = "sqlInputId")
   @OrderBy("id")
   public Set<DbSqlFieldMapping> getFieldMapping()
   {
      return fieldMapping;
   }


and the owned side:
Code:
@ManyToOne
   @JoinColumn(name="sqlInputId", insertable=false, updatable=false)
   public DbSqlInput getSqlInput()
   {
      return sqlInput;
   }


The foreign key is generated correctly and the owned entities are deleted, when I delete an input. But: when I do something like that:
Code:
input.setFieldMapping(null);
or
Code:
input.getFieldMapping().remove(m);



the owned entities are NOT deleted. Only the foreign keys are set null.

Question: What do I need to change, that the owned entities are deleted when remove from the set?

Thank you in advance
Mathias


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 4:50 pm 
Regular
Regular

Joined: Sat Nov 19, 2005 2:46 pm
Posts: 69
From chapter "11.11 Transitive persistence" of the Hibernate Reference PDF (Hibernate 3.0.5 version)
Quote:
Entities have their own lifecycle, support shared references (so removing
an entity from the collection does not mean it can be deleted), and there is by default no cascading of state from
one entity to any other associated entities. Hibernate does not implement persistence by reachability by default.

Later in the same chapter it says:
Quote:
A special cascade style, delete-orphan, applies only to one-to-many associations, and indicates that the delete()
operation should be applied to any child object that is removed from the association.

Hope that helps. Don't forget to rate :-)

_________________
Stewart
London, UK


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.