私はHibernateHQLクエリを持っていますが、これは完全に機能しているようですが、現在Hibernate Criteria APIで少し実験しており、CriteriaAPIで同じHQLクエリを表現したいと思います。この特定の例では、HQLクエリに2つの結合があり、2番目の結合は最初の結合のエイリアスを使用します。CriteriaAPIと同じものを実現したいと思います。これは可能ですか?
元のクエリは次のとおりです。
select mt
from MessageThread mt
inner join mt.messageThreadsStatuses ts
inner join ts.threadLocations tl
where ts.user.userId = :userId and tl = 0";
これが書き直されたクエリですが、私には機能しません:
Criteria c = sf.getCurrentSession().createCriteria(MessageThread.class)
.createAlias("messageThreadsStatuses", "ts").setFetchMode("ts", FetchMode.JOIN)
.createAlias("ts.threadLocations", "tl").setFetchMode("tl", FetchMode.JOIN)
.add(Restrictions.eq("ts.user.userId", userId))
.add(Restrictions.eq("tl", 0));
たとえば、2番目のエイリアスを次のように定義しようとしました。
.createAlias("threadLocations", "tl").setFetchMode("tl", FetchMode.JOIN)
しかし、成功しませんでした。