-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Adding Existing Children to a Parent
PostPosted: Sat Sep 25, 2010 6:58 am 
Newbie

Joined: Sat Sep 25, 2010 6:42 am
Posts: 1
I have a class structure of

Parent ---- Child ---- Grandchild ---- Greatgrandchild etc

with a many-to-many relationship between the Parent and the Child, so I have an intersecting table between the two conatinging the primary keys of the Parent and Child, which Hibernate manages for me. All well and good so far.

As I access the persistant object form a GUI connected via RMI, I have Cascade=all and fetch lazy = false everywhere.

I would like to be able to add (and remove) an existing child to a Parent, ideally just using the PK of the child. The action is relational land is simply to insert (or delete) an entry in the intersecting table, but I would like to be able to do this via Hibernate so that the underlying implementation of the many-to-many relationship is not exposed. The children and grandchildren objects all have their own DAOs all I want form the parent is the abilty to add/ remove and fetch, but to change the child POJO.

Can I construct a child based on the primary key of an existing object, add it to the parent and then save the parent? I fear if I do this, all the attributes in the children, including the connected grandchildren will be lost.

In summary, my question is : how can I use hibernate to affect the intersecting table directly while mantaining my object model and not exposing the underlying intersecting table?

Many thanks for any advise received.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.