Sorry of this appears a bit simple a question, but is there a way to load objects from the db with Hibernate by specifying the class as a variable of the query?
I.e.:
I have
ClazzA, ClazzB, ClazzC
All three classes are mapped to tables ClazzA, ClazzB and ClazzC in the db
I would like to have a variable like so:
Class clazz=obj.getClass();
and then be able to populate a query by specifying the class as part of the query construction:
List objs=session.createQuery(…) … .list();
Is there a way to do this?
There is no elegant way to do it with HQL queries, but you can use Criteria API:
See also: