-->
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.  [ 1 post ] 
Author Message
 Post subject: Duplicate entity in bag when using identifier Id strategy
PostPosted: Wed Aug 31, 2005 11:45 am 
Newbie

Joined: Wed Aug 31, 2005 11:27 am
Posts: 2
Using hibernate 3.0.5:

I have a problem using "identifier" id with a lazy associations mapped as a bag. The bidirectionnal association is mapped as usual : children side is a "bag" inverse lazy one-to-many association. parent side is a many-to-one association.

> Entity parent = session.load(2);
> Entity child = new Entity();
> child.setParent(parent);
> parent.getChildren.add(chlid);

> session.save(child);

> int childrenCount = parent.getChildren.size();

So, here childrenCount value is 2, which is incorrect. Note that no session.flush() has occured.

Using the same mapping, but using the "sequence" Id strategy, the value returned is childrenCount is 1, which is correct.

Is this a known problem or a bad programming practice?

What I see using a debugger is that using sequence, the saved object is not persisted when the collection is initialized, and the collection contains only the local addition. A contrario, with the identifier stategy, the saved object is inserted in the database in order to get its Id, and is found when the collection is initialized. With the local addition, the bag contains twice the saved object child.

Thanks for your attention.

Alexandre


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.