FlukeFan wrote:
Hi,
I think the reason you're getting an error is that you need to alias the main query and the sub-query with different aliases, then correlate them.
So, the main criteria needs an alias ('Person' in my example), and the detached criteria has a different alias ('SubPerson' in my example), and the detached criteria needs to join on these, so the key part of the query is:
Code:
.Add(Expression.EqProperty("SubPerson.id", "Person.id")) 
Hope that helps.
Regards,
    Richard
This does not work. My DetachedCriteria does not know the alias of the criteria. Or do I have to create an alias for the detached critiera in my main criteria?
Tried this:
Code:
Criteria crit = _session.createCriteria(Person.class, "con");
      
      DetachedCriteria buy =
          DetachedCriteria.forClass(Person.class, "dc")
             .add(Restrictions.eq("dc.id", "con.id"))
              .createAlias("clothes", "bi")
              .add(Restrictions.eq("bi.name", "shirt"))
              .setProjection(Projections.id());
      crit.add(Subqueries.notExists(buy)); 
Thank you very much...