1

I have a detachedCriteria like this

private final DetachedCriteria DETACHED_CRITERIA_FOR_FILTERING_STUDENTS=   DetachedCriteria.forClass(Students.class)
        .add(filters)
        .add(super.criterionForFilteringStudents)
        .setProjection(idProjection())
        .setResultTransformer(transformer(Students.class));

Later i use it like normally do i have a Table named RelationShip which have a Integer which is not a foreing key just a Integer column.

final Criteria criteria = session.createCriteria(RelationShip.class)
     .add(filters)          
     .add(Subqueries.propertyIn("c03",DETACHED_CRITERIA_FOR_FILTERING_STUDENTS));

Everything works like a charm but i did realize that this query is completely cached i mean i used like this of course in a different context.

public List<Student>getStudents()
{
     final Criteria criteria = session.createCriteria(Students.class)
        .add(filters)
        .add(super.criterionForFilteringStudents)
        .setProjection(idProjection())
        .setResultTransformer(transformer(Students.class))
        .setCacheable(true)
        .setCacheRegion(region);
     return criteria.list();
}

Of course i could do something like

public List<RelationShip>getRelationShip()
{
     final Criteria criteria = session.createCriteria(RelationShip.class)
       .add(filters)          
     .add(Restrictions.in("c03",getStudents()));
     return criteria.list();
}

But i came with this concern how could i use a DetachedCriteria which is a query which is completely cacheable or cached is this possible?

I have try

DETACHED_CRITERIA_FOR_FILTERING_STUDENTS.getExecutableCriteria(session).setCacheable(true).setCacheRegion(region)

But with no success.

Is this possible?

chiperortiz
  • 4,751
  • 9
  • 45
  • 79

0 Answers0