-->
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: understanding persistence
PostPosted: Sat Feb 10, 2007 8:09 pm 
Newbie

Joined: Fri Jan 26, 2007 3:51 pm
Posts: 16
Hi,

I'm trying to understand how persistence works and have been experimenting with a small app. Please read on and help me to understand if my findings are correct.

Note that given a class Foo that has a collection of Bar objects like so:

@Entity
@Table (name = "FOOS")
public class Foo
{
...
@OneToMany(mappedBy = "foo")
private Collection<Bar> BARS = new ArrayList<Bar>();
...
//getters and setters
}

Let us say that we have loaded the collection with three Bar objects. Now, let us say that we want to remove one of the Bar objects from the collection. My experimental app seems to indicate that it is not enough to simply call the remove(Object o) method on the collection, but one has to also call the remove(Object o) method on the EntityManager as well in order to get that record out of the BARS table of the database. Correct?

Furthormore, what if I wanted to remove the entire instance of the Foo object (this would include any and all remaining Bar objects in the collection)? Do I have to clear the entire collection of Bars first and those instances from the BARS table before I can remove the instance of the Foo object from the FOOS table of the database? Is there a way to do this all in one go with one method call? Does cascading help in some way in this scenario?

Please advise,

Alan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is all explained in the reference documentation, did you ahve a look.
Alternatively, get Java Persistence with Hibernate from your favorite book store

_________________
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.