Results 1 to 5 of 5

Thread: How Persistent Bag works in Hibernate World

  1. #1
    Join Date
    Jun 2007
    Posts
    4

    Default 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. #2
    Join Date
    Oct 2006
    Location
    Salzburg, AT
    Posts
    21

    Default

    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,
    Andreas Wurzer
    andeee's Blog

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    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 at 10:13 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  4. #4
    Join Date
    Jun 2007
    Posts
    4

    Default followup

    Quote 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

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    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 at 10:13 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •