DetachedCriteria doesn't create alias on subcriteria

Description

DetachedCriteria has two createCriteria methods:

public DetachedCriteria createCriteria(String associationPath) throws HibernateException
public DetachedCriteria createCriteria(String associationPath, String alias) throws HibernateException

However, the code for both was identical - they called the inner criteria's createCriteria(String) method. The version with the alias did not call the inner's version with the alias. The following patch snipped shows the change:

public DetachedCriteria createCriteria(String associationPath, String alias)
throws HibernateException {
- return new DetachedCriteria( impl, criteria.createCriteria(associationPath) );
+ return new DetachedCriteria( impl, criteria.createCriteria(associationPath, alias) );
}

This bug was discovered while trying to link a 2-deep subquery to its parent via aliases. (Surfacing this issue might only be possible with the patch in place - I'm not sure. Seems like a bug regardless, as it definitely fixed my alias reference issue.) I'll get an example posted shortly.

Environment

None

Activity

Show:
Philip Saville
January 17, 2007, 3:27 AM

The work around doesn't work when trying to add criterion to the subcriteria which is now only an alias.

I am trying to convert my code to use DetachedCriteria instead of Criteria and what was working for one or two deep joins does not work when using DetachedCriteria.

Originally, when using "createCriteria" method - the error was:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: ALIAS_NAME_FOR_SUBCRITERIA of: SUBCRITERIA_OBJECT; nested exception is org.hibernate.QueryException: could not resolve property: ALIAS_NAME_FOR_SUBCRITERIA of: SUBCRITERIA_OBJECT
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:651)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:408)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:328)

Now, when trying the work around "createAlias" method - the error is:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: FIELD_IN_SUBCRITERIA_TABLE of: CRITERIA_OBJECT; nested exception is org.hibernate.QueryException: could not resolve property: FIELD_IN_SUBCRITERIA_TABLE of: CRITERIA_OBJECT
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:651)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:408)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:328)

When will this issue be fixed? Can't someone just make the above mentioned change and have it be part of the next build?

Rastislav Siekel
July 31, 2007, 9:30 AM

I have the same problem. Patch from Description not help me. Aliases in subquery (4-deep IN clause) is always "this0__".

Diego Plentz
September 8, 2007, 11:28 PM

Done in trunk/branch 3.2

Rastislav Siekel
September 29, 2009, 10:52 AM

I find this correction just now, because I have some new requirements to this part of code, and all go perfect. Thank's very much

Steve Ebersole
March 21, 2011, 7:04 PM

Bulk closing stale resolved issues

Assignee

Diego Plentz

Reporter

John

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure