In 15.17. Collection member references of documentation, in example Example 495. Collection references example the second query is not equivalent to first query because of the select clause. In the first query select clause selects ph which is a reference to Phone entity, but in second one the select clause selects pr which is a reference to Person. The second query should be changed to
List<Phone> phones = session.createQuery(
"select ph " +
"from Person pr, " +
"in (pr.phones) ph, " +
"in (ph.calls) c " +
"where pr.address = :address " +
" and c.duration > :duration" )
.setParameter( "address", address )
.setParameter( "duration", duration )
.list();
|