Uploaded image for project: 'JBoss Enterprise Application Platform 4 and 5'
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-838

HHH-957 - SubqueryExpression throws ClassCastException on DetachedCriteria subqueries

    XMLWordPrintable

Details

    Description

      see http://opensource.atlassian.com/projects/hibernate/browse/HHH-957

      The toSqlString() method in SubqueryExpression contains a line that casts a Criteria object to CriteriaImpl in order to call the getSession() method. However, if DetachedCriteria is used as a subquery in a Criteria query, the underlying Criteria object will be CriteriaImpl.Subcriteria, thus a ClassCastException will be thrown.

      I have created a bug fix. Add the following method to SubqueryExpression:

      private SessionImpl getSessionImpl(Criteria criteria) {
      SessionImpl session = null;
      if (criteria instanceof CriteriaImpl)

      { CriteriaImpl impl = (CriteriaImpl)criteria; session = impl.getSession(); }

      else if (criteria instanceof CriteriaImpl.Subcriteria)

      { CriteriaImpl.Subcriteria sub = (CriteriaImpl.Subcriteria)criteria; //Alert! Recursive call here! session = getSessionImpl(sub.getParent()); }

      return session;
      }

      And then replace the offending line in toSqlString() with a call to the new method.

      Attached is SubqueryExpression with proposed changes in place.

      Attachments

        Activity

          People

            apatrici Anthony Patricio
            apatrici Anthony Patricio
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: