[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3154) Criteria API use - duplicate SQL alias might be generated for subquery

Denis Mukhin (JIRA) noreply at atlassian.com
Tue Mar 4 07:52:33 EST 2008


Criteria API use - duplicate SQL alias might be generated for subquery
----------------------------------------------------------------------

                 Key: HHH-3154
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3154
             Project: Hibernate3
          Issue Type: Bug
          Components: query-criteria
    Affects Versions: 3.2.6
            Reporter: Denis Mukhin


>From org/hibernate/criterion/SubqueryExpression.java - Hibernate 3.2.6 sources:
-------------------------------
private void createAndSetInnerQuery(CriteriaQuery criteriaQuery, final SessionFactoryImplementor factory) {
...
//with two-deep subqueries, the same alias would get generated for
//both using the old method (criteriaQuery.generateSQLAlias()), so
//that is now used as a fallback if the main criteria alias isn't set
String alias;
if ( this.criteriaImpl.getAlias() == null ) {
alias = criteriaQuery.generateSQLAlias();
}
else {
alias = this.criteriaImpl.getAlias() + "_";
}
...
}
-------------------------------

This implementation means that if DetachedCriteria (passed to SubqueryExpression constructor) created without alias explicitely specified, generated SQL alias might be duplicate of what is generated for outer query because:
1. Class org.hibernate.impl.CriteriaImpl has 2 arg constructor (entity/class name and session implementor). It creates object with alias set to "this". This constructor is used from DetachedCriteria.forEntityName(String) or DetachedCriteria.forName(Class), thus DetachedCriteria is created with not-null default alias.
2. As comment in original code says generateSQLAlias() also may return duplicate names.

The simplest solution I see is to always generate there SQL alias based, for instance, on SubqueryExpression class name and increasing counter stored in static field.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list