PersistentBag.remove() and removeAll() load the whole collection

Description

When removing an entity from the database, it is a requirement in hibernate that you remove the entity from any persistent collections it is in so that you don't get errors about transient objects being referenced by a collection.

However, calling remove() on a persistent collection seems to load the whole collection into memory.

The use of very large (too big to load all at once) lazy collections is apparently not well supported in hibernate because it is difficult to use them without loading the whole collection into memory rather than load it incrementally. Nevertheless, it is possible to request subsets of collections and having the ability to remove() without loading the lazy collection would be a bonus for those of us who do use large lazy collections that way.

Here is the offending code:

public boolean remove(Object o) {
initialize( true );
if ( bag.remove( o ) ) {
dirty();
return true;
}
else {
return false;
}
}
{/code}

Environment

None

Activity

Show:
Mauricio Hiroshi Nagaoka
July 2, 2011, 7:27 AM

I also came across this issue when trying to remove from a Bag mapped as cascade="all,delete-orphan", even when specifying lazy="extra".
Looking at the source code (Hibernate 3.5.1, in my case), it seems PersistentBag doesn't honor the "laziness" specified on the collection mapping like PersistentSet and PersistentList do.

@Dobes as a workaround, I would suggest you to use a <set cascade="all,delete-orphan" lazy="extra"> instead. The shortcoming of this approach is that Hibernate needs to check for uniqueness when you add to the Set. This is done by issuing a select 1 from... so it may not be that expensive.

Brett Meyer
April 7, 2014, 5:42 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Brett Meyer
July 8, 2014, 3:11 PM

Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

Rejected

Assignee

Unassigned

Reporter

Dobes Vandermeer

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure