-->
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: one-shot delete is different for bag?
PostPosted: Mon Sep 01, 2003 10:04 am 
Newbie

Joined: Mon Sep 01, 2003 12:31 am
Posts: 5
Hi,

I am trying to do one-shot delete and found the following in section 12.4 of the document.

"Suppose we add a single element to a collection of size twenty and then remove two elements. Hibernate will issue one INSERT statement and two DELETE statements (unless the collection is a bag). This is certainly desirable. ".

Question is why the behavior is different for a bag. I am using a bag for my parent/child relationship. Does it mean I should use some other type (e.g., set etc.)? Or is there another way to clear a collection that's mapped using a bag?

I want to do a one-shot delete the existing collection and add a new collection during an update.

Thanks,
Tahir

_________________
Thanks,
Tahir


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
When you use a bag, Hibernate has no way to uniquely identify each row, thus it cannot efficiently perform single row operations.

The term on-shot-delete actually refers to the opposite of what you quote from the docs. A one-shot-delete operation is deleteing all elements in a collection and then re-inserting them.

One-shot-delete is available for all Collection types. To apply a one-shot-delete, do something likes this:
Code:
Parent parent = session.load( Parent.class, parentId );
List children = new ArrayList();
children.add( child1 );
children.add( child2 );
parent.setChildren( children );


Or if you map using a list or set and want to avoid using one-shot-delete semantics, then do something like:
Code:
Parent parent = session.load( Parent.class, parentId );
parent.getChildren().add( child1 );
parent.getChildren().remove( child2 );
[/code]


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.