HHH-8847 - Exception thrown when trying to select a treated property

This commit is contained in:
Steve Ebersole 2015-11-09 22:41:59 -06:00
parent f940c72aa9
commit 4132a4293a
2 changed files with 16 additions and 3 deletions

View File

@ -116,12 +116,14 @@ public class RootImpl<X> extends AbstractFromImpl<X,X> implements Root<X>, Seria
@Override
public void prepareAlias(RenderingContext renderingContext) {
// do nothing...
// NOTE : we call `original#prepareAlias` here and during render
// since in some cases only one or the other will be called
original.prepareAlias( renderingContext );
}
@Override
public String render(RenderingContext renderingContext) {
original.prepareAlias(renderingContext);
original.prepareAlias( renderingContext );
return getTreatFragment();
}

View File

@ -17,8 +17,8 @@ import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.jpa.test.metamodel.Thing;
import org.hibernate.jpa.test.metamodel.ThingWithQuantity;
import org.hibernate.jpa.test.metamodel.ThingWithQuantity_;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
@ -200,6 +200,17 @@ public class TreatKeywordTest extends BaseEntityManagerFunctionalTestCase {
em.close();
}
@Test
public void testSelectSubclassPropertyFromDowncast() {
EntityManager em = getOrCreateEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Integer> criteria = builder.createQuery( Integer.class );
Root<Thing> root = criteria.from( Thing.class );
Root<ThingWithQuantity> subroot = builder.treat( root, ThingWithQuantity.class );
criteria.select( subroot.<Integer>get( "quantity" ) );
em.createQuery( criteria ).getResultList();
em.close();
}
}