Edited at

DetachedCriteriaを使って副問い合わせをする場合は、Projections必須

More than 5 years have passed since last update.

Projectionを介さないと NullPointerExceptionになる。

Criteria criteria = createCriteria(Hoge.class);

criteria.add(Restrictions.eq("id", 1));

DetachedCriteria fooCriteria = DetachedCriteria.forClass(Foo.class, "foo");
fooCriteria.add(Restrictions.eq("id", 1));

criteria.add(Subqueries.exists(fooCriteria.setProjection(Projections.property("id"))));
return criteria.list();