diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/MethodNode.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/MethodNode.java index c0fbf9b56b..75d55c1f16 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/MethodNode.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/MethodNode.java @@ -141,20 +141,25 @@ public class MethodNode extends AbstractSelectExpression implements FunctionNode String propertyName = CollectionProperties.getNormalizedPropertyName( methodName ); if ( expr instanceof FromReferenceNode ) { FromReferenceNode collectionNode = (FromReferenceNode) expr; + fromElement = collectionNode.getFromElement(); // If this is 'elements' then create a new FROM element. if ( CollectionPropertyNames.COLLECTION_ELEMENTS.equals( propertyName ) ) { - handleElements( collectionNode, propertyName ); + QueryableCollection queryableCollection = fromElement.getQueryableCollection(); + + String path = collectionNode.getPath() + "[]." + propertyName; + LOG.debugf( "Creating elements for %s", path ); + + if ( !fromElement.isCollectionOfValuesOrComponents() ) { + getWalker().addQuerySpaces( queryableCollection.getElementPersister().getQuerySpaces() ); + } + + setDataType( queryableCollection.getElementType() ); + selectColumns = fromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect ); } else { // Not elements(x) - fromElement = collectionNode.getFromElement(); - - final CollectionPropertyReference cpr = fromElement.getCollectionPropertyReference( propertyName ); - setDataType( cpr.getType() ); - selectColumns = cpr.toColumns( fromElement.getTableAlias() ); - -// setDataType( fromElement.getPropertyType( propertyName, propertyName ) ); -// selectColumns = fromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect ); + setDataType( fromElement.getPropertyType( propertyName, propertyName ) ); + selectColumns = fromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect ); } if ( collectionNode instanceof DotNode ) { @@ -190,22 +195,6 @@ public class MethodNode extends AbstractSelectExpression implements FunctionNode } } - private void handleElements(FromReferenceNode collectionNode, String propertyName) { - FromElement collectionFromElement = collectionNode.getFromElement(); - QueryableCollection queryableCollection = collectionFromElement.getQueryableCollection(); - - String path = collectionNode.getPath() + "[]." + propertyName; - LOG.debugf( "Creating elements for %s", path ); - - fromElement = collectionFromElement; - if ( !collectionFromElement.isCollectionOfValuesOrComponents() ) { - getWalker().addQuerySpaces( queryableCollection.getElementPersister().getQuerySpaces() ); - } - - setDataType( queryableCollection.getElementType() ); - selectColumns = collectionFromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect ); - } - @Override public void setScalarColumnText(int i) throws SemanticException { if ( selectColumns == null ) { // Dialect function