I have found that self-referential entities work just fine.  Just make
sure that you lazily load everything so that hibernate doesn't have to
load your entire object graph into memory with every call.  If you have
a single parent object with a getter/setter, you'll want to use proxies,
but if your relationships are all mapped with collections then just make
sure that lazy-load="true".

Jeff Schnitzer
[EMAIL PROTECTED]

> -----Original Message-----
> From: Bear Giles [mailto:[EMAIL PROTECTED]
> Sent: Monday, November 24, 2003 10:09 AM
> To: [EMAIL PROTECTED]
> Subject: [Hibernate] Design question: am I asking for trouble?
> 
> A quick design question whether I'm asking for trouble....
> 
> I have a class with self-referential sets.  Call it:
> 
>   class Person {
>      // @hibernate.identifier
>      private Long id;
> 
>      // @hibernate.set table="parents"
>      //  key=child_id value=parent_id cascade="all"
>      private Set parents;
> 
>      // @hibernate.set table="parents"
>      //  key=parent_id value=child_id cascade="all"
>      private Set children;
> 
>      // @hiberate.set table="siblings"
>      //  key=id value="sibling_id" cascade="all"
>   }
> 
> I don't have problems when I do an initial population of the
> database via db-utils, but I'm wondering if it's maintainable
> since editing one object necessarily modifies other objects.  Will
> this confuse hibernate?  (I want to say "no," but for me that's
> still an assumption.)  I know everything is fine once I reload
> everything from the database, but I'm not sure about the impact on
> a live system.
> 
> Example: I add Alice as a parent of Bob.  If I now load Alice from
> disk, she'll have Bob as a child.  But if Alice is already in
> memory how long until she lists Bob as a child?  Should I call
> 'evict()' on Alice when Bob adds her as a parent, and if so what
> does that do to other references to her?
> 
> 
> On a related note, the sets contain the ID of the associated
> objects.  This isn't a problem at the persistence layer, but the
> external representation needs the sets to contain Persons, not
> Longs.  Is there a conventional way of handling this, or is it
> just something that needs to be manually done when converting the
> object from internal to external representation?
> 
> Bear
> 
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive?  Does it
> help you create better code?  SHARE THE LOVE, and help us help
> YOU!  Click Here: http://sourceforge.net/donate/
> _______________________________________________
> hibernate-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/hibernate-devel



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to