lundi 8 juin 2015

JPA, Hibernate mapping inheritance based on EER

Hello guys how should I map such a model in EER

this is generic problem in EER

And this is my specific implementation:

this is real model in relational database

In the above model Client is a union (disjointed) of NaturalPerson/Firm, i.e. Client can be NaturalPerson or Firm but both inherit from UserAccount, and Firm can be inherited more over by Provider, and NaturalPerson can be inherited by Worker... the problem i how to map this...

I have make Client as one-to-one relationship that has such relationship to NaturalPerson AND to Firm and I enforce that one of them must be null. But when I go further I consider how to implement Provider it should extend Firm but this firm shouldn't be discriminator in UserAccount... you know Firm can be only firm and function as a client or it can be simultanously client and provider...

Seems the best will be to have in Firm @Entity second discriminator with (JustClient, ClientAndProvider) discriminator values, and maybe some constraint on Firm @Entity that @Client never can be null

Aucun commentaire:

Enregistrer un commentaire