[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3037) SizeExpression doesn't work for a collection that's defined on a base class
Daniel Kandel (JIRA)
noreply at atlassian.com
Fri Dec 28 13:56:05 EST 2007
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list