Archie Cobbs (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-16318 (
https://hibernate.atlassian.net/browse/HHH-16318?atlOrigin=eyJpIjoiMmQ4ZD...
)
Re: Wrong SQL query generated when type() tested inside selectCase() expression (
https://hibernate.atlassian.net/browse/HHH-16318?atlOrigin=eyJpIjoiMmQ4ZD...
)
Some more debug info relating to the 5.6.15 test case…
It appears that the problem is that the root does not have an alias (yet) when the JQL is
generated. So then PathTypeExpression.render() invokes Root.getPathIdentifier() which
returns getAlias() , which is null at that time.
The resulting JQL looks like this:
select case when type(null) in (:param0)
then treat(generatedAlias0 as org.hibernate.bugs.Dog).numSpots
else 0 end
from Animal as generatedAlias0
Note the type(null) , which causes the problem. This, even though later we have Animal as
generatedAlias0.
The bug in the test case can be worked around with this patch:
iff --git a/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java
b/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java
index b30891f..06c285c 100644
--- a/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java
+++ b/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java
@@ -47,6 +47,7 @@ public class JPAUnitTestCase {
final CriteriaQuery<Integer> query = cb.createQuery(Integer.class);
final Root<Animal> animal = query.from(Animal.class);
+ animal.alias("a");
final Expression<Boolean> isDog = JPAUtil.instanceOf(entityManager,
animal, Dog.class);
final Expression<Integer> numSpots = cb.<Integer>selectCase()
So the fix is to somehow force alias generation sooner.
(
https://hibernate.atlassian.net/browse/HHH-16318#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16318#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:fd7c927 )