Reputation: 1735
I'm trying to figure out if I can make a method that fetches or finds all the entries in a central database I have.
My entities are as follows:
Nomination(Abstract) -> Type1Nomination, Type2Nomination, Type3Nomination, so on.
Nomination has a table is mapped to the DB also, and has the common properties/columns of every type of nomination. The rest is self-explanatory.
The way I see it, I would have to cast the types of nominations to the base class? And this would be done in a Service class (because you cannot make a DAO of an abstract class), am I correct?
Upvotes: 0
Views: 310
Reputation: 15363
You can do this in JPA/Hibernate and JPA inheritance. It should be as simple as querying the Nomination entity.
Select n From Nomination n
should return a list of abstract nomination objects.
I've seen folks using a type column in conjunction with the in
keyword to get certain subgroups in your case something like
Select n from nomination where n.type in :types
where types was a collection of "Type1Nomination" "Type2Nomination" but because these are sibling queries it can lead to some nasty LEFT OUTER JOIN queries
Upvotes: 2