Announcement Announcement Module
Collapse
No announcement yet.
How Persistent Bag works in Hibernate World Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How Persistent Bag works in Hibernate World

    Here is my class looks like:

    public class MyList extends ArrayList{


    List<MyObject> 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

  • #2
    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 <bag> element in your hibernate mapping file, so hibernate wraps your list in a PersistentBag class -> 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,

    Comment


    • #3
      The reason persistent bag "got involved" 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.
      Last edited by karldmoore; Aug 29th, 2007, 10:13 AM.

      Comment


      • #4
        followup

        Originally posted by karldmoore View Post
        The reason persistent bag "got involved" 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 MyTaskList<S> 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

        Comment


        • #5
          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?
          Last edited by karldmoore; Aug 29th, 2007, 10:13 AM.

          Comment

          Working...
          X