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.
|