We're setting up a new project and decided to use eclipselink for JPA. When creating our domain model we ran into a problem.
We have a base class called organisation. We also have Supplier and Customer which both extend organisation. When JPA created the tables I saw that it uses a discriminator, the problem with this is that a supplier can also be a organisation.
So what I basically want is (these are database tables to get the idea):
A little example to help clarify this:
We have a Customer called SparklingGlass. SparklingGlass buys computers from us so SparklingGlass is saved as our Customer. We in turn buy our windows from SparklingGlass, so SparklingGlass is also our Supplier. This is what we want to realize in our system.
Is this in any way possible in JPA and ifnot, what is the best practice in these cases?
BTW we use the JOINED inheritance type
Your data model is wrong. A Supplier is not a sub-type of Organization but is a Role played by an Organization.
An organization can play many roles, such as customer, vendor, supplier, employer.