Alex Karki (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=632b44a...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDVmN2ZkOTVm...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15718?atlOrigin=eyJpIjoiZDVmN2...
) HHH-15718 (
https://hibernate.atlassian.net/browse/HHH-15718?atlOrigin=eyJpIjoiZDVmN2...
) Polymorphic queries with condition do not work (
https://hibernate.atlassian.net/browse/HHH-15718?atlOrigin=eyJpIjoiZDVmN2...
)
Issue Type: Bug Affects Versions: 6.1.5 Assignee: Unassigned Components: query-hql
Created: 14/Nov/2022 18:53 PM Environment: - pure
'org.hibernate:hibernate-core:6.1.5.Final'
- JDK: Temurin-17.0.4.1+1
- Windows 10
- MySQL 5.7.39
- 'mysql:mysql-connector-java:5.1.46'
- XML mapping
Priority: Major Reporter: Alex Karki (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=632b44a...
)
When a query uses an interface name instead of a class name, it is not possible to use
that object in "where" condition. For example, all these queries do work in
Hibernate 5.6 and fail in 6.1:
final String [] queries = {
"from " + I. class. getName(),
"from " + I. class. getName() + " where displayName is null
" ,
"from " + I. class. getName() + " i" ,
"from " + I. class. getName() + " i where i.displayName is
null " ,
"select i from " + I. class. getName() + " i" ,
"select i from " + I. class. getName() + " i where
i.displayName is null " ,
"select displayName from " + I. class. getName(),
"select i.displayName from " + I. class. getName() + "
i" ,
"select i.displayName from " + I. class. getName() + " i
where i.displayName is null " ,
};
for ( String query : queries) {
try ( final var session = sessionFactory.openSession()) {
session.createQuery(query).list();
}
}
The exception is
jakarta.persistence.PersistenceException: Converting
`org.hibernate.sql.ast.SqlTreeCreationException` to JPA `PersistenceException` : Could not
locate TableGroup - model.I(396480023707500)
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:165)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:374)
at org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1032)
Mapped via XML:
public interface I {
String getDisplayName();
}
public class A implements I {
private Long id;
private String displayName;
...
}
public class B implements I {
private Long id;
private String displayName;
...
}
<hibernate-mapping> <class name= "model.A" table= "A" >
<id name= "id" type= "long" column= "id" >
<generator class= "native" /> </id> <property name=
"displayName" type= "string" column= "display_name" />
</class> </hibernate-mapping>
(
https://hibernate.atlassian.net/browse/HHH-15718#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15718#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#100210- sha1:583150f )