i have a parent entity Service and a child ExtendedService in a SINGLE_TABLE inheritance.
A third entity ServiceCollector need to include both entites Service and ExtendedService. This is a fixed requirement, and with this design i can realize it using polymorphism.
THE PROBLEM: Very often i need to retrieve ONLY the parent class Service, so i query it by discriminator column… i think this is a bad design for my purpouse, isn’t true?
This is a simple example, indeed i have a lot of Service subclasses, think for example to a shop that sell different product, each product can have a different properties.
Thanks in advance.
If every ExtendedService isn’t valid as a response to a query for Service, sounds more like you have Templating through Inheritance, rather than Polymorphism. A simple fix is to make Service abstract, so you have
AbstractServiceand an empty classServicethat extends it and just defines theDiscriminatorValue. (Then ExtendedService extends AbstractService, etc.)Mapping the discriminator column to query it isn’t exactly the end of the world, if everything else is working fine for you. Personally I’d file it more towards “Inelegant” than “Bad Design” but that’s just opinion.