From: Gavin K. <Gav...@ex...> - 2002-12-18 09:50:00
|
I'm (again) considering deprecating toplevel collections and subcollections=20 in Hibernate 2.0. I was never completely happy with this feature after I implemented it, but it had taken so much effort to get it to work that I left it in. The case against toplevel collections is: * the relational model is broken - there is no foreign key constraint from=20 collection element row to the owning row * subcollections complicate code in SessionImpl _significantly_ The case for keeping them is: * they let you persist a Java "collection of collections" * they let you have a single table / collection mapping that can be used by=20 different owning classes * instances of a toplevel collection can be passed between different owners=20 (even between owners of a different class, potentially) without needing to=20 remove and recreate the collection rows * they currently work and I havn't needed to touch the complicated code for=20 a long time now So: Do people USE this feature?? Have people really actually found uses=20 for this stuff, or is it actually just making Hibernate harder to understand=20 for the first time? Even if it has been useful, is perhaps *still* undesirable,=20 because of concerns about data integrity? Perhaps we simply shouldn't=20 be encouraging this kind of relational model..... I need advice on this. Gavin ********** CAUTION - Disclaimer ********** This message may contain privileged and confidential information. If you are not the intended recipient of this message (or responsible for delivery of the message to such person) you are hereby notified that any use, dissemination, distribution or reproduction of this message is prohibited. If you have received this message in error, you should destroy it and kindly notify the sender by reply e-mail. Please advise immediately if you or your employer do not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of Expert Information Services Pty Ltd ("The Company") shall be understood as neither given nor endorsed by it. The Company advises that this e-mail and any attached files should be scanned to detect viruses. The Company accepts no liability for loss or damage (whether caused by negligence or not) resulting from the use of any attached files. **EIS******** End of Disclaimer ********** |
From: Christian B. <chr...@bl...> - 2002-12-18 13:46:53
|
On 18 Dec (20:49), Gavin King wrote: > So: Do people USE this feature?? Have people really actually found uses > for this stuff, or is it actually just making Hibernate harder to > understand > for the first time? Even if it has been useful, is perhaps *still* > undesirable, > because of concerns about data integrity? Perhaps we simply shouldn't > be encouraging this kind of relational model..... I tried once to use toplevel collections, because I had a "collection of collections" and the collection could be referenced by two different classes. The mapping wasn't hard to understand, but the restrictions on the load/delete/update killed them for me. Using a Hibernate Session is straightforward if you don't use toplevel collections, the only thing to keep in mind is handling bidirectional associations with setparent/setchild on both ends. Toplevel collections add a lot more overhead to this handling routines, which is what kept me from using it. As soon as I realized that, I stopped even thinking about using a toplevel collection and change my models accordingly. I bet a lot of people are doing the same, the benefits of toplevel collections would be nice, but dealing with them is not. My point is: For every aspect thats on your "plus" side for toplevel collections, find a different way of implementing it without a toplevel collection, then compare the effort for both methods and decide wether this justifies an additional idiom (tl collections) in Hibernate or not. Data Integrity: I'm not a DB newbie, so I noticed the missing foreign key on first sight. But this is just the implementation of toplevel collections, which could be changed if the idiom itself is worth it. -- Christian Bauer tu...@in... |
From: Jim D. <jim...@po...> - 2002-12-19 08:12:37
|
Sorry for taking a tangent here but after spending a day trying to figure out what SessionImpl was doing and to work out why my bi-directional associations didn't work I conceded defeat and moved to a unidirectional model. How do you 'setparent/setchild on both ends'? Is guidance on this in some documentation that I missed? Thanks, jim jim...@po... On Wed, Dec 18, 2002 at 02:45:46PM +0100, Christian Bauer wrote: > On 18 Dec (20:49), Gavin King wrote: > Using a Hibernate Session is straightforward if you don't use toplevel > collections, the only thing to keep in mind is handling bidirectional > associations with setparent/setchild on both ends. |
From: Mark W. <mor...@SM...> - 2002-12-19 08:57:19
|
Jim Downing wrote: >Sorry for taking a tangent here but after spending a day trying to >figure out what SessionImpl was doing and to work out why my >bi-directional associations didn't work I conceded defeat and moved to >a unidirectional model. > >How do you 'setparent/setchild on both ends'? Is guidance on this in >some documentation that I missed? > > Check out http://www.xylax.net/hibernate/. Tom has pulled together some pretty useful examples and they also have notes on bi-directional associations. -Mark |
From: Christian B. <chr...@bl...> - 2002-12-19 09:03:18
|
On 19 Dec (00:57), Mark Woon wrote: > >How do you 'setparent/setchild on both ends'? Is guidance on this in > >some documentation that I missed? > > Check out http://www.xylax.net/hibernate/. Tom has pulled together some > pretty useful examples and they also have notes on bi-directional > associations. It is also an item in the FAQ. -- Christian Bauer tu...@in... |
From: Jim D. <jim...@po...> - 2002-12-19 09:20:16
|
On Thu, Dec 19, 2002 at 10:02:10AM +0100, Christian Bauer wrote: > On 19 Dec (00:57), Mark Woon wrote: > > >How do you 'setparent/setchild on both ends'? Is guidance on this in > > >some documentation that I missed? > > > > Check out http://www.xylax.net/hibernate/. Tom has pulled together some > > pretty useful examples and they also have notes on bi-directional > > associations. > > It is also an item in the FAQ. Thanks - I'd used the advance in Tom's manual to do the mapping, but I was trying to maintain the relationship in my persistent objects (rather than making the client do it, as in the FAQ), which was probably the cause of my problems. Thanks, jim |
From: Christian B. <chr...@bl...> - 2002-12-19 09:32:52
|
On 19 Dec (09:20), Jim Downing wrote: > Thanks - I'd used the advance in Tom's manual to do the mapping, but I > was trying to maintain the relationship in my persistent objects > (rather than making the client do it, as in the FAQ), which was > probably the cause of my problems. Thats exactly what I'm doing: class Child { public setParent(Parent newParent) { // Remove myself from old Parent if (this.parent != null) { this.parent.getChildren().remove(this); } // Add to new Parent newParent.getChildren().add(this); // Set new Parent this.parent = newParent; } } This is similar to the Composite Pattern (or better, a part of it): http://www.idg.net/english/crd_composite_948016.html -- Christian Bauer tu...@in... |
From: Max R. A. <ma...@eo...> - 2002-12-19 09:47:59
|
Should we implement this paradigm in the codegenerator ? (of course as an option) Maybe something like this: <property name="parent" class="eg.Parent"> <metaattribute name="CodeGen.genCompositeGetSet" value="true"/> </property> Where the codegen would generate something like the code below if "CodeGen.genCompositeGetSet" is set for the property and/or relationship. /max ----- Original Message ----- From: "Christian Bauer" <chr...@bl...> To: <hib...@li...> Sent: Thursday, December 19, 2002 10:31 AM Subject: Re: Bi-directional relationships (was Re: [Hibernate] Are toplevel collections / subcollections a Bad Thing?) > On 19 Dec (09:20), Jim Downing wrote: > > > Thanks - I'd used the advance in Tom's manual to do the mapping, but I > > was trying to maintain the relationship in my persistent objects > > (rather than making the client do it, as in the FAQ), which was > > probably the cause of my problems. > > Thats exactly what I'm doing: > > class Child { > > public setParent(Parent newParent) { > > // Remove myself from old Parent > if (this.parent != null) { > this.parent.getChildren().remove(this); > } > > // Add to new Parent > newParent.getChildren().add(this); > > // Set new Parent > this.parent = newParent; > } > } > > This is similar to the Composite Pattern (or better, a part of it): > > http://www.idg.net/english/crd_composite_948016.html > > -- > Christian Bauer > tu...@in... > > > ------------------------------------------------------- > This SF.NET email is sponsored by: Geek Gift Procrastinating? > Get the perfect geek gift now! Before the Holidays pass you by. > T H I N K G E E K . C O M http://www.thinkgeek.com/sf/ > _______________________________________________ > hibernate-devel mailing list > hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > |