SizeExpression doesn't work for a collection that's defined on a base class
---------------------------------------------------------------------------
Key: HHH-3037
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3037
Project: Hibernate3
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.2
Reporter: Daniel Kandel
When using SizeExpression in a criteria on a collection defined in a base class, a
MappingException (unknown collection role) is thrown.
A short example:
abstract class A {
@OneToMany
Set<B> bSet;
}
class C extends A {}
A SizeExpression is used for a criteria on class C (referencing the collection of class
B).
In SizeExpression.toSqlString, the role is calculated this way:
String role = criteriaQuery.getEntityName(criteria, propertyName) + '.' +
criteriaQuery.getPropertyName(propertyName)
This causes the role to be: C.bSet, which causes the MappingException.
I think the role should be calculated using the PropertyMapping (the same way it is in
AbstractEmptinessExpression):
SessionFactoryImplementor factory = criteriaQuery.getFactory();
String entityName = criteriaQuery.getEntityName(criteria, propertyName);
PropertyMapping ownerMapping = ( PropertyMapping )
factory.getEntityPersister(entityName);
Type type = ownerMapping.toType( propertyName );
if ( !type.isCollectionType() ) {
throw new MappingException("Property path [" + entityName + "." +
propertyName + "] does not reference a collection");
}
String role = ( (CollectionType) type ).getRole();
This seems to work for me (the role is A.bSet).
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira