Hi Everyone, (sorry for the duplicate, can't delet...
# questions
u
Hi Everyone, (sorry for the duplicate, can't delete it) I'm not sure if I'm hitting a bug, a feature, or a limitation of DetachedCriteria.... (Grails 6, Gorm ) Occasionally, when i'm passing in a DetachedCriteria as a subquery to an
inList("property", mySubQuery)
I'm given an error:
ConverterNotFoundException: No converter found capable of converting from type [org.hibernate.criterion.DetachedCriteria] to type [java.lang.Long]
This is usually when there is some nesting of associations, but I haven't been able to extract a simple reproducible case from our application. The issue arises in
AbstractHibernateCriterionAdapter
as follows
Copy code
protected void applySubCriteriaToJunction(PersistentEntity entity, AbstractHibernateQuery hibernateCriteria, List<Query.Criterion> existing,
            Junction conjunction, String alias) {

        for (Query.Criterion subCriterion : existing) {
            if (subCriterion instanceof Query.PropertyCriterion) {
                Query.PropertyCriterion pc = (Query.PropertyCriterion) subCriterion;
                if (pc.getValue() instanceof QueryableCriteria) {
                    pc.setValue(toHibernateDetachedCriteria(hibernateCriteria, (QueryableCriteria<?>) pc.getValue()));
                }
                else {
                    AbstractHibernateQuery.doTypeConversionIfNeccessary(entity, pc);
                }
            }
Here,
pc.getValue()
is an already converted Hibernate DetatchedCriteria, not the original Gorm DetachedCriteria - it looks like the gorm original has been converted, but I've yet been unable to trace where and when. the Hibernate converted DC is not
instanceof QueryableCriterion
and so the engine looks instead to convert to a list of scalars. Does anyone have any initial thoughts on bug/limitation or feature here?
s
Looks like a bug. My guess is that something is re-using the criterion. Perhaps another nested clause somewhere, or a count operation based on the original criterion. Given that
pc.setValue(toHibernateDetachedCriteria(hibernateCriteria, (QueryableCriteria<?>) pc.getValue()));
mutates the original, any subsequent usage would cause the error you are seeing. I don't think the "why" it was already converted is really important here though, if it CAN happen then this code should be changed to accommodate that and skip values already of the Hibernate Criteria types, I think you should file a bug.