All the strange constants are simply strings, but will do. The stange thing is that the subquery executed by itself will generate the inner join based on the createAlias() but passed as a property into the propertyIn() it doesn't.
Code:
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Location.class);
DetachedCriteria subQueryCriteria = DetachedCriteria.forClass(AgmtContractLine.class);
subQueryCriteria.createAlias("versions", "versions");
subQueryCriteria.add(Restrictions.eq("versions.endUse", "Sales"));
subQueryCriteria = subQueryCriteria.setProjection(Property.forName("versions.sourceLocation"));
detachedCriteria.add(Subqueries.propertyIn("addrId", subQueryCriteria));
Gives me the following where clause (without the expected inner join):
Code:
from ADDRESS this_
where this_.ADDR_ID in
(select versions1_.SRC_ADDR_ID as y0_
from AGMT_CNTRCT_LINE this0__
where versions1_.END_USE_CODE = ?)
Where if the subQueryCriteria is executed standalone I get (with the expected inner join):
Code:
select versions1_.SRC_ADDR_ID as y0_
from AGMT_CNTRCT_LINE this_ inner join AGMT_CNTRCT_LINE_V versions1_ on this_.AGMT_CNTRCT_LINE_ID = versions1_.AGMT_CNTRCT_LINE_ID
where versions1_.END_USE_CODE = ?
When executed as an actual subquery I the following exception (which is expected since I don't end up with the version1_ alias from the join):
Caused by: java.sql.SQLException: ORA-00904: "VERSIONS1_"."END_USE_CODE": invalid identifier
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:831)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2496)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2840)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:108)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1158)
at org.hibernate.loader.Loader.doQuery(Loader.java:357)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:199)
at org.hibernate.loader.Loader.doList(Loader.java:1417)
... 31 more