patricknoir wrote:
Of course I know what hierarchy means, that an admin "is a" operator, but there are some cases that I need to look for operators that aren't admins. I got a solution adding a field specificRole and I use it like a discriminator, I know that it isn't a "clean" solution, probably I will use a sqlRestriction condition to check discriminator field if I won't find a way to avoid polymorphism
My O/R map file :
In looking at your mapping file, while Admin may extend Operator in the Java sense, it extends User with respect hibernate so you should be able to add
polymorphism="explicit" to your class mapping and then, when you use
Code:
session.createCriteria(Operator.class).list();
You will only retrieve Operator instances.
If you had Admin extending Operator in the hibernate mappings, then this wouldn't work. the code would retrieve all Operator objects and subclasses.
Be sure to read about how this will effect the behavior in collections associated to other objects.