Hi all.
I have an A POJO with a b attribute which is a collection (Set) of B elements. Like this: public class A { Set<B> bs = new HashSet<B>(); // other fields and property access methods }
The size of a.bs set could be some millions so I load it in a LAZY mode, of course.
I have annotated the bs field with DELETE_ORPHAN cascade so I can remove a b element from a.bs collection. This is: a.bs.remove(b);
The problem is that this code iterate over whole collection looking for the B element, so every elements are loaded from DB. And, like there are millions of records,. this raises an Out Of Memory exception.
Is there any way to set custom access (with org.hibernate.property.PropertyAccessor, for example) to avoid the load of the elements, except just which I want to remove? the approach could be similar to LazyCollectionOption.EXTRA.
Summarizing: I need to look for over a lazy collection but not hitting the DB until find what I'm searching.
Any idea?
_________________ Born to lose... live to win!
|