views:

34

answers:

1

Hi All,

I'm having trouble creating a model for a couple entities that is sane in both Hibernate and the Database. Any help is appreciated.

A company entity and table exists, which provides both a company name and a "company code". The company code must be unique.

Company's may act as 2 different entities, clients or partners.

We'd like to have separate Client and Partner Entities.

The complicating factors I see are

1) Companies can be both a client and a partner.

2) The company code must remain unique.

3) We want to be able to create new clients and partners passing company_code's as a parameter. eg. new Client("WALMART") and new Partner("WALMART") that should map to the same company.

Single-Table and Multi-Table Inheritance don't work because they don't map a Merchant and Client with the same company code to a single company.

Thanks all.

+2  A: 

Could you have a Company table that the Partner and Client entities have a many-to-one link to? This would allow you to set the company on the partner and client as a descriptor (more of a has-a, although it is closer to a typing) without needing inheritance.

aperkins