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. ...
-
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
-
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...
Similar Threads
-
By Application Development in forum JDBC JAVA
Replies: 0
Last Post: 05-24-2005, 01:15 PM
-
By Application Development in forum Java
Replies: 2
Last Post: 12-27-2004, 12:29 AM
-
By Application Development in forum JDBC JAVA
Replies: 0
Last Post: 12-26-2004, 11:26 PM
-
By Application Development in forum JDBC JAVA
Replies: 0
Last Post: 10-18-2004, 03:15 AM
-
By Application Development in forum JDBC JAVA
Replies: 0
Last Post: 10-18-2004, 03:14 AM