|
|
How Persistent Bag works in Hibernate World
Here is my class looks like:
public class MyList extends ArrayList{Listlt;MyObjectgt; contents;
add()
remove()
}
when I called remove(). it indicated that PersistentBag.remove() got called, and then it crashed.
Can someone let me know why the persistentBag got involved? what area should pay more attention if I define my own arrayList and applied in the Hibernate later, thanks
What a persistent bag is - from the Hibernate API Doc:
An unordered, unkeyed collection that can contain the same element multiple times. The Java collections API, curiously, has no Bag. Most developers seem to use Lists to represent bag semantics, so Hibernate follows this practice.
I assume you have mapped your list as a lt;baggt; element in your hibernate mapping file, so hibernate wraps your list in a PersistentBag class -gt; you get this behaviour on remove().
For further information, can you please provide us a stack trace of your crash and (snippets of) your hibernate mapping file?
HTH
Cheers,
The reason persistent bag quot;got involvedquot; I would presume is that you are dealing with a persistent entity and Hibernate has it's own Collections implementations to allow it to lazy load items.
Originally Posted by karldmooreThe reason persistent bag quot;got involvedquot; I would presume is that you are dealing with a persistent entity and Hibernate has it's own Collections implementations to allow it to lazy load items.
Yes you are right that I am dealing with a persistent entity. for instance, the Entity is TaskContainer, and an MyTaskListlt;Sgt; extends ArrayList. When I tried to remove tasks from TaskContainer, the persistentBag.remove() got called. and then it crashed.
can you give me any ideas on how to define my own TaskList within persistent entity, thanks so lot for your help.
or how to overwrite the Hibernate 's collection implementation
I've never tried to do such a thing, not really sure what you can do. I'd have a read of the Hibernate forums and see if this has been brought up before. Why do you need to do this anyway? |
|