Here's a little stumper for the Hibernate team. I posted this in another thread, but I think it got lost, so I'm re-posting it as its own topic.
How can I query joined subtypes using custom SQL (the createSQLQuery() method)? That is, suppose I have the query:
Code:
SELECT {subtype.*}
FROM SUBTYPE {subtype}
INNER JOIN SUPERTYPE {super} ON {subtype}.id = {super}.id
Hibernate will expand {subtype.*} to including both subtype and supertype columns. However, I have no way of knowing what name Hibernate is going to substitute for the supertype table.... How do I tell it to substitute {super} with the name of the joined supertype?
It looks like I can cheat as follows:
Code:
SELECT {subtype.*}
FROM SUBTYPE {subtype}
INNER JOIN SUPERTYPE {subtype}_1_ ON {subtype}.id = {subtype}_1_.id
...but now I'm just presuming that Hibernate will always generate a name for the joined supertype in exactly the same way -- by suffixing "_1_" -- yuck! What I want is a way of telling hibernate how to substitute the name of the supertype table, just like I can already with the subtype.
Does this question make sense? Is there an answer yet?
(And yes, for various tricky reasons, we do need to use custom SQL and not HQL; yes, the subtype has to be in a separate table -- so there's no way around this question for us.)