12

This question is titled similar to this one, but it's no duplicate as the other OP actually wanted something else (anyway, there's no answer to my question there). What I want is to recycle my already constructed Criteria in Subqueries.exists(DetachedCriteria).

I know that Criteria is basically DetachedCriteria with an attached Session, so I'd expect something like Criteria#toDetached() or a factory method on the other side, but I can't find anything.

Community
  • 1
  • 1
maaartinus
  • 44,714
  • 32
  • 161
  • 320

2 Answers2

2

As per OP , it helped him to solve his problem.

One of the way could be the one given in NHibernate: Convert an ICriteria to a DetachedCriteria Thats for Nhibernate, but same can done in Hibernate Also.

Community
  • 1
  • 1
Deendayal Garg
  • 5,030
  • 2
  • 19
  • 33
2

Trivially rewritten in Java:

public class MyDetachedCriteria extends DetachedCriteria {
    public OcDetachedCriteria(Criteria criteria) {
        super((CriteriaImpl) criteria, criteria);
        ((CriteriaImpl) criteria).setSession(null);
    }
}
maaartinus
  • 44,714
  • 32
  • 161
  • 320