HHH-12076 Fix index out of bounds exception and allow table group joins for collection joins as well

This commit is contained in:
randymay 2017-11-03 16:22:22 -04:00 committed by Christian Beikov
parent 7f814107a8
commit 44d78d9b85
3 changed files with 14 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import org.hibernate.MappingException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.internal.ast.tree.ImpliedFromElement;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.collection.AbstractCollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.entity.Joinable;
@ -422,9 +423,16 @@ public class JoinSequence {
}
private boolean isSubclassAliasDereferenced(Join join, String withClauseFragment) {
if ( join.getJoinable() instanceof AbstractEntityPersister ) {
AbstractEntityPersister persister = (AbstractEntityPersister) join.getJoinable();
int subclassTableSpan = persister.getSubclassTableSpan();
Object joinable = join.getJoinable();
if ( joinable instanceof AbstractCollectionPersister ) {
final AbstractCollectionPersister collectionPersister = (AbstractCollectionPersister) joinable;
if ( collectionPersister.getElementType().isEntityType() ) {
joinable = ( collectionPersister ).getElementPersister();
}
}
if ( joinable instanceof AbstractEntityPersister ) {
final AbstractEntityPersister persister = (AbstractEntityPersister) joinable;
final int subclassTableSpan = persister.getSubclassTableSpan();
for ( int j = 1; j < subclassTableSpan; j++ ) {
String subclassAlias = AbstractEntityPersister.generateTableAlias( join.getAlias(), j );
if ( isAliasDereferenced( withClauseFragment, subclassAlias ) ) {

View File

@ -557,7 +557,9 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
}
else {
referencedFromElement = fromElement;
joinAlias = extractAppliedAlias( dotNode );
if ( fromElement != null ) {
joinAlias = extractAppliedAlias( dotNode );
}
// TODO : temporary
// needed because currently persister is the one that
// creates and renders the join fragments for inheritance

View File

@ -80,7 +80,6 @@ public class HbmMappingJoinClassTest extends BaseCoreFunctionalTestCase {
}
@Test
@FailureExpected( jiraKey = "HHH-12076")
public void testClassExpressionInOnClause() {
doInHibernate( this::sessionFactory, session -> {
List<SettlementTask> results = session.createQuery(