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
jlp - 18 Nov 2004 22:30 GMT
Daniel Wotziak a écrit :
> Hello,
>
[quoted text clipped - 36 lines]
>
> Daniel
Your problem sounds like the parent/child pattern.
There is an example at the end of Hibernate Reference Manual.
Take a look...