I have the following query using createSQLQuery.
A and B are both inheriting from a common super class and I would like to select A and B with the addEntity method.
I therefore need to select A and B with the {alias.*} syntax as I get column clashes otherwise.
Code:
SQLQuery query = Database.getHibernateSessionProvider().getSession().createSQLQuery(""
+ "select {a.*}, {b.*} from A a "
+ " inner join SUPER a_super ON a_super.id = a.id "
+ " inner join SUPER b_super ON b_super.id = b.id "
+ " inner join A a ON a.key = b.key ");
query.addEntity("a", A.class). addEntity("b", B.class).list();
My question is how I can influence the alias of the super type (a_super and b_super)? It seems that Hibernate is expanding {a.*} to a.xxx for field in the sub type and a_1_.xxx in the super type. This means in order to get my query working I need to hardcode those aliases which is not the desired solution as I don't know if this is stable or not.
Code:
SQLQuery query = Database.getHibernateSessionProvider().getSession().createSQLQuery(""
+ "select {a.*}, {b.*} from A a "
+ " inner join SUPER a_1_ ON a_1_.id = a.id "
+ " inner join SUPER b_1_ ON b_1_.id = b.id "
+ " inner join A a ON a.key = b.key ");
query.addEntity("a", A.class). addEntity("b", B.class).list();
Can anyone help with this? Is there a way to define the alias of the super type myself?