| By design, DetachedCriteria are intended to be serializable and this is something we have been leveraging in our result paging system for years. We are now hitting an issue when adding subqueries to the detached criteria where our session replication breaks on the serialization attempt. In contrast to the rest of the DetachedCriteria object graph, the following classes are not serializable:
org.hibernate.loader.criteria.CriteriaQueryTranslator
org.hibernate.engine.spi.QueryParameters
Instances of these can be present inside of any SubqueryExpression instance, which makes its way into a DetachedCriteria instance by way of:
instance<DetachedCriteria>.criteria<CriteriaImpl>.criterionEntries<List<CriterionEntry>>
An example criteria that ends up with a PropertySubqueryExpression in that List:
DetachedCriteria mainCriteria = DetachedCriteria.forClass(ParticipantAsset.class);
DetachedCriteria subQ = DetachedCriteria.forClass(Ownership.class);
subQ.add(Restrictions.eq("pid", pid));
subQ.setProjection(Property.forName("guid"));
mainCriteria.add(Property.forName("participant.guid").in(subQ));
|