HHH-8847 - Exception thrown when trying to select a treated property
(cherry picked from commit 4132a4293a
)
This commit is contained in:
parent
823bf5e0d8
commit
7612f8c183
|
@ -116,12 +116,14 @@ public class RootImpl<X> extends AbstractFromImpl<X,X> implements Root<X>, Seria
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepareAlias(RenderingContext renderingContext) {
|
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
|
@Override
|
||||||
public String render(RenderingContext renderingContext) {
|
public String render(RenderingContext renderingContext) {
|
||||||
original.prepareAlias(renderingContext);
|
original.prepareAlias( renderingContext );
|
||||||
return getTreatFragment();
|
return getTreatFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.jpa.test.metamodel.Thing;
|
import org.hibernate.jpa.test.metamodel.Thing;
|
||||||
import org.hibernate.jpa.test.metamodel.ThingWithQuantity;
|
import org.hibernate.jpa.test.metamodel.ThingWithQuantity;
|
||||||
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.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -200,6 +200,17 @@ public class TreatKeywordTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue