I have a named-native-query entry for a special case query that I need to use. The problem arises when I have two tables that have the same column names.
Quote:
Table A:
A_ID
CAP
..
Table B:
B_ID
CAP
..
I wanted to put this query in an orm.xml instead of hard coding all this:
Code:
String query = "SELECT {a.*}, {b.*} ...";
Session hibernateSession = (Session) entityManager.getDelegate();
SQLQuery sqlQuery =
hibernateSession.createSQLQuery( query ).addEntity("a", A.class).addEntity("b", B.class);
With the "hibernate" way, I have the put the braces around so that it's smart enough to know what to map to where. However, if I attempted to put this in an orm.xml up front, and then simply create the sql-result-set-mapping and entity-result, I have no way to tell it which alias' map to which class.
So what ends up happening is, whatever value A.capacity has, ends up in B.capacity entity also. Because hibernate is going by the name, nothing else. It isn't applying alias' at all. The query for A.CAP comes first, so when it is trying to create the B class, it's just finding the first "CAP" in the result set and setting that value.
So, ultimately what I'm saying is, with orm.xml, is there no way to define what alias goes with what entity-result?