Consider this hierarchy:
In Java
Code:
Party
Business Individual
Client SPBusiness SPIndividual
SPClient
SO, we have a class hierarchy above.
We wanted to place Client and SPClient from Party,Business, SPBusiness,Individual, SPIndividual and place them in separate tables.
The reason we extend Business for Client is simply for re-use.
So, our hibernate mapping class defines Party, and subclasses Business,Individual,SPBusiness and SPIndividual, with discriminators to table PARTY
We then mapped Client as a separate class, along with its descendents to a table CLIENTS. We reproduce the mappings in Client (the attributes, etc) that also appear in Business and Party.
So, all is well, we store data, it goes in the correct place
But, now if we do an HQL "Select from Business", hibernate will actually return the union of all objects from both tables. Even though our mapping for Client does not live in the Business hierarchy, hibernate somehow "determines" that Client extends Business, and gives me all the clients.
Does this make sense? Can anybody tell me how to prevent this, how to separate or break this hierachy? or do i have to move code from Party and Business into Client and maintain it separately?