-->
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.  [ 4 posts ] 
Author Message
 Post subject: Collection item not saved
PostPosted: Sat Apr 22, 2006 11:28 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
I have the following situation:

Classes:
Code:
class foo:
Set<Bar> bars;

class Bar:
Foo foo;


This is what I'm doing

Code:
Foo foo1 = somemethodThatChoosesFoo(ID);
Foo foo2 = somemethodThatChoosesFoo(ID);

Set<Bar> bars = foo1.getbars();

// now I'm picking some bar from the set bars
Bar bar = somemethodThatChoosesABar(bars, ID);

bar.setFoo(foo2);
dao.makePersistent(bar); // = session.saveOrUpdate(bar)

// Now displaying bars from foo1
for(bar : bars){
displayBar(bar);
}


What I want is: bar gets removed from "getBars()" from foo1 and gets added to "getBars()" from foo2.

What I get is: bar doesn't get removed from foo1 but is added to foo2. After a page reload (and transaction commit) the "getBars()" from foo1 is updated and I get the wanted behaviour.

Isn't it possible to update the "getBars()" from foo1 in memory first? (before committing the transaction)

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 6:54 am 
Newbie

Joined: Tue Nov 15, 2005 4:21 am
Posts: 11
You have to remove it manually


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 2:49 pm 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
Thanks for the suggestion. What I did was turning off the caching for the _collection_ of bars that foo has.

foo
<id>....</id>
<prop>...</prop>

<set bars..>
<!-- no caching here -->
</set>

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 3:08 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
In the chapter 16 of hibernate reference documentation, it sayed:
[quote]
19.5.2. Lists, maps, idbags and sets are the most efficient collections to update
From the discussion above, it should be clear that indexed collections and (usually) sets allow the most efficient operation in terms of adding, removing and updating elements.

There is, arguably, one more advantage that indexed collections have over sets for many to many associations or collections of values. Because of the structure of a Set, Hibernate doesn't ever UPDATE a row when an element is "changed". Changes to a Set always work via INSERT and DELETE (of individual rows). Once again, this consideration does not apply to one to many associations.

After observing that arrays cannot be lazy, we would conclude that lists, maps and idbags are the most performant (non-inverse) collection types, with sets not far behind. Sets are expected to be the most common kind of collection in Hibernate applications. This is because the "set" semantics are most natural in the relational model.

However, in well-designed Hibernate domain models, we usually see that most collections are in fact one-to-many associations with inverse="true". For these associations, the update is handled by the many-to-one end of the association, and so considerations of collection update performance simply do not apply[/quote]

If u want to update all datas of your set, it is impossible with hibernate. U have tu change ur set to Bag or List, then you can do "update"


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