次のシナリオで Criteria API を使用しようとしています。
- 2 つのテーブル
Schedule
とRoute
(クラスとマッピングを含む) があります。 Route
は と多対 1 の関係にありSchedule
ます。Route
には整数プロパティがありますsequence
。
次に、関連する Route オブジェクトが次の条件を満たすすべての Schedule オブジェクトを取得する必要があります。
route.sequence=no. of all Route objects associated with the given Schedule object
次の基準コードを試しました:
Criteria crit = getSession().createCriteria(getPersistentClass())
.createCriteria("routes", "route")
.setProjection(Projections.projectionList()
.add( Projections.rowCount(), "routeCount"))
.add(Restrictions.not(Restrictions.ltProperty("route.sequence", "routeCount")));
しかし、次の sql が生成されます。
select count(*) as y0_
from schedule this_
inner join route route1_ on this_.ID=route1_.scheduleId
where route1_.sequence<y0_
次のエラーがスローされます。
Unknown column 'y0_' in 'where clause'
何か提案があれば、私を助けてください。