Fixed HHH-10577

This commit is contained in:
Christian Beikov 2017-01-25 18:20:01 +01:00 committed by Chris Cranford
parent f9fce8c657
commit 18e8be0037
2 changed files with 38 additions and 30 deletions

View File

@ -46,38 +46,36 @@ public abstract class AbstractMapComponentNode extends FromReferenceNode impleme
boolean implicitJoin,
String classAlias,
AST parent) throws SemanticException {
if ( parent != null ) {
throw attemptedDereference();
}
if ( mapFromElement == null ) {
final FromReferenceNode mapReference = getMapReference();
mapReference.resolve( true, true );
final FromReferenceNode mapReference = getMapReference();
mapReference.resolve( true, true );
FromElement sourceFromElement = null;
if ( isAliasRef( mapReference ) ) {
final QueryableCollection collectionPersister = mapReference.getFromElement().getQueryableCollection();
if ( Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
sourceFromElement = mapReference.getFromElement();
}
}
else {
if ( mapReference.getDataType().isCollectionType() ) {
final CollectionType collectionType = (CollectionType) mapReference.getDataType();
if ( Map.class.isAssignableFrom( collectionType.getReturnedClass() ) ) {
FromElement sourceFromElement = null;
if ( isAliasRef( mapReference ) ) {
final QueryableCollection collectionPersister = mapReference.getFromElement().getQueryableCollection();
if ( Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
sourceFromElement = mapReference.getFromElement();
}
}
else {
if ( mapReference.getDataType().isCollectionType() ) {
final CollectionType collectionType = (CollectionType) mapReference.getDataType();
if ( Map.class.isAssignableFrom( collectionType.getReturnedClass() ) ) {
sourceFromElement = mapReference.getFromElement();
}
}
}
if ( sourceFromElement == null ) {
throw nonMap();
}
mapFromElement = sourceFromElement;
}
if ( sourceFromElement == null ) {
throw nonMap();
}
mapFromElement = sourceFromElement;
setFromElement( sourceFromElement );
setDataType( resolveType( sourceFromElement.getQueryableCollection() ) );
this.columns = resolveColumns( sourceFromElement.getQueryableCollection() );
setFromElement( mapFromElement );
setDataType( resolveType( mapFromElement.getQueryableCollection() ) );
this.columns = resolveColumns( mapFromElement.getQueryableCollection() );
initText( this.columns );
setFirstChild( null );
}
@ -102,10 +100,6 @@ public abstract class AbstractMapComponentNode extends FromReferenceNode impleme
protected abstract String[] resolveColumns(QueryableCollection collectionPersister);
protected abstract Type resolveType(QueryableCollection collectionPersister);
protected SemanticException attemptedDereference() {
return new SemanticException( expressionDescription() + " expression cannot be further de-referenced" );
}
protected SemanticException nonMap() {
return new SemanticException( expressionDescription() + " expression did not reference map property" );
}

View File

@ -11,6 +11,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import antlr.collections.AST;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.internal.NameGenerator;
@ -58,6 +59,19 @@ public class MapEntryNode extends AbstractMapComponentNode implements Aggregated
return Map.Entry.class;
}
@Override
public void resolve(
boolean generateJoin,
boolean implicitJoin,
String classAlias,
AST parent) throws SemanticException {
if (parent != null) {
throw new SemanticException( expressionDescription() + " expression cannot be further de-referenced" );
}
super.resolve(generateJoin, implicitJoin, classAlias, parent);
}
@Override
@SuppressWarnings("unchecked")
protected Type resolveType(QueryableCollection collectionPersister) {