休止状態の「基準」(hqlではない)でクエリを実行しようとしていますが、何を実行するか、何を使用するかがわかりません。
select * from foo where column1 = 8 and column2 not in (
select column2 from foo where column1 = 11
)
2つの異なるクエリで作成し、Java関数を使用して結果を取得しましたが、1つの基準クエリが必要です。
休止状態の「基準」(hqlではない)でクエリを実行しようとしていますが、何を実行するか、何を使用するかがわかりません。
select * from foo where column1 = 8 and column2 not in (
select column2 from foo where column1 = 11
)
2つの異なるクエリで作成し、Java関数を使用して結果を取得しましたが、1つの基準クエリが必要です。
実際のエンティティマッピングが何であるかを知っているモジュロ(そしてこれはもちろん完全にテストされていません)、それはおそらく似たようなものによって解決されます
Session hibernateSession = ... (however you get it).
DetachedCriteria d = DetachedCriteria.forClass(Foo.class)
.add(Restrictions.eq("column1", 11))
.setProjection(Projections.property("column2"));
Criteria criteria = hibernateSession.createCriteria(Foo.class)
.add(Restrictions.eq("column1", 8))
.add(Subqueries.propertyNotIn("column2", d));
List<Foo> result = criteria.list();
「column1」と「column2」はSQLフィールド名であり、これらの場所で必要なのはJavaプロパティであるため、これはほぼ確実に調整が必要です。
条件を作成してすべてを選択Criteria cr = session.createCriteria(Your.class); List list = cr.list();
次に、制限を追加できます。つまり、列1=8などの場合は次のようになります。cr.add(Restrictions.eq("YourCondition", YourCondition));
最後に、次のようにnotin句を指定できます。crit.add(Restrictions.not(Restrictions.in("YourNotInCondition", YourNotInCondition)));