Hibernate Design-Problem - JDBC JAVA

This is a discussion on Hibernate Design-Problem - JDBC JAVA ; Hello, I have a little design-Problem with hibernate. I have several company-objects. Each company can own several subcompanies. Each company can be owned be several superCompanies. The realationship has an order, that means the super- and the subcompanies are sorted. ...

+ Reply to Thread
Results 1 to 2 of 2

Hibernate Design-Problem

  1. Default Hibernate Design-Problem

    Hello,

    I have a little design-Problem with hibernate.

    I have several company-objects. Each company can own several
    subcompanies. Each company can be owned be several superCompanies. The
    realationship has an order, that means the super- and
    the subcompanies are sorted. I can add a superCompany to each company.

    So I have two classes:

    Company
    -------
    Members: Id, Name, City, SuperCompanies (Set), SubCompanies (Set)

    Methods:
    getSubCompanies -> List
    getSuperCompanies -> List
    addSuperCompany (Company, ordinalNumber)
    removeSuperCompany (Company)


    CompanyCompany (Relationship-Class)
    --------------
    Members: SuperCompany, SubCompany, ordinalNumber

    If I delete a company, all subCompanies of this company should be
    delete, too.

    How do I realize this using Hibernate? Does the company-class must have
    two Sets, one for the superCompanies and one for the subCompanies?
    Do both sets have to be in the mapping-files (company.hbm.xml - two
    1:n-relationships, companyCompany.hbm.xml - two n:1 realationships, one
    for each Set)?
    How do I have to set the cascading-attribute, so that if I delete one
    company, all subCompanies are
    deleted, too? Is there a mistake in my logical sequence of thoughts?

    Many thanks in advance for your help!

    Daniel

  2. Default Re: Hibernate Design-Problem

    Daniel Wotziak a écrit :
    > Hello,
    >
    > I have a little design-Problem with hibernate.
    >
    > I have several company-objects. Each company can own several
    > subcompanies. Each company can be owned be several superCompanies. The
    > realationship has an order, that means the super- and
    > the subcompanies are sorted. I can add a superCompany to each company.
    >
    > So I have two classes:
    >
    > Company
    > -------
    > Members: Id, Name, City, SuperCompanies (Set), SubCompanies (Set)
    >
    > Methods:
    > getSubCompanies -> List
    > getSuperCompanies -> List
    > addSuperCompany (Company, ordinalNumber)
    > removeSuperCompany (Company)
    >
    >
    > CompanyCompany (Relationship-Class)
    > --------------
    > Members: SuperCompany, SubCompany, ordinalNumber
    >
    > If I delete a company, all subCompanies of this company should be
    > delete, too.
    >
    > How do I realize this using Hibernate? Does the company-class must have
    > two Sets, one for the superCompanies and one for the subCompanies?
    > Do both sets have to be in the mapping-files (company.hbm.xml - two
    > 1:n-relationships, companyCompany.hbm.xml - two n:1 realationships, one
    > for each Set)?
    > How do I have to set the cascading-attribute, so that if I delete one
    > company, all subCompanies are
    > deleted, too? Is there a mistake in my logical sequence of thoughts?
    >
    > Many thanks in advance for your help!
    >
    > Daniel

    Your problem sounds like the parent/child pattern.
    There is an example at the end of Hibernate Reference Manual.
    Take a look...

+ Reply to Thread

Similar Threads

  1. Hibernate Help: Hibernate list of lists problem
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 05-24-2005, 01:15 PM
  2. [HIBERNATE] [EVALUATION] - Gavin King Censors Hibernate Forum
    By Application Development in forum Java
    Replies: 2
    Last Post: 12-27-2004, 12:29 AM
  3. [HIBERNATE] [EVALUATION] - Gavin King Censors Hibernate Forum
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 12-26-2004, 11:26 PM
  4. Re: Database Design Problem with Hibernate Primary Key and Foreign K
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 10-18-2004, 03:15 AM
  5. Re: Database Design Problem with Hibernate Primary Key and Foreign K
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 10-18-2004, 03:14 AM