none
Multiple Hierarchical one-to-one Relationships RRS feed

  • Question

  • Hibernate version: 1.2

    Problem Statement:

    I'm stuck with the following scenario:

    I have one parent with a primary key. Now parent's Primary Key is mapped to two Child objects and is also their Primary Key.

    Hibernate provides a way to map one-to-one between two objects. In that case if I create a "Child" object then hibernate will automatically create a "Parent" object by using Parent key.

    But the problem is with one "Parent" and two "Child", if I create any "Child" the other child will always missing, parent and both children must have same ID and must always be created in single transaction.

    _____________
    | Parent
    |------------------
    | pid (PK)
    | text
    |_____________


    _____________
    | Child1
    |------------------
    | pid (FK + PK)
    | textC1
    |_____________


    _____________
    | Child2
    |------------------
    | pid (FK + PK)
    | textC2
    |_____________

    Thanking in advance for your wise replies
    Thursday, January 10, 2008 1:38 PM

All replies

  • You're probably not asking this question in the right place, as it's more of a coding question?  I'm not totally sure what you're asking, could you please restate the question. 

     

    One thing that I do notice is that you have a Parent, and two children with the same primary key. 

    Do the child table also have other information in them?  If not then the objects shoudl be normalized since the parent primary key can refer directly to the child data, there appears to be no need for the hierarchy?  If you have some other reasons for the child object, then please disregard the statement.

     

    Thanks,

     

    Martin Platt.

    Thursday, January 10, 2008 10:30 PM
  •  ImaginationTOCulmination wrote:
    Hibernate version: 1.2

    Problem Statement:

    I'm stuck with the following scenario:

    I have one parent with a primary key. Now parent's Primary Key is mapped to two Child objects and is also their Primary Key.

    Hibernate provides a way to map one-to-one between two objects. In that case if I create a "Child" object then hibernate will automatically create a "Parent" object by using Parent key.



    This forum is not the best for that question.

    Please keep to architecture posts which are independant of API and general implementation questions
    Friday, January 11, 2008 11:12 PM