Emond Papegaaij (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWMwNDY3MWFi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15726?atlOrigin=eyJpIjoiMWMwND...
) HHH-15726 (
https://hibernate.atlassian.net/browse/HHH-15726?atlOrigin=eyJpIjoiMWMwND...
) Disjunction with treat results in too restrictive query (
https://hibernate.atlassian.net/browse/HHH-15726?atlOrigin=eyJpIjoiMWMwND...
)
Issue Type: Bug Affects Versions: 5.3.28, 6.1.5, 5.6.14 Assignee: Unassigned Components:
hibernate-core Created: 16/Nov/2022 01:05 AM Priority: Major Reporter: Emond Papegaaij (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
When selecting on a disjunction of a property in a base class and a property in a subclass
(treat), the restriction on the dtype is placed incorrectly causing on the matches of the
subclass to be returned. Similar behavior was already present in older versions of
Hibernate ORM (tested in 5.3.28 and 5.6.14), however it seems 6.1.5 is more consistent in
rendering the incorrect restriction, which causes queries in our application to miss
results. In 5.3.28 these queries did return results because the dtype restriction was
missing entirely (which also is incorrect).
In the example of a query rendered by 6.1.5 below, it is clear that this can only return
records of type PLDAPDirectory:
select
p1_0.id,
p1_0.DTYPE,
p1_0.active,
p1_0.openldap
from
( select
*
from
PAccountDirectory t
where
t.DTYPE= 'PLDAPDirectory' ) p1_0
where
p1_0.active=?
or case
when p1_0.DTYPE= 'PLDAPDirectory' then p1_0.openldap
else null
end =?
Corresponding Java code:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<PAccountDirectory> query = cb.createQuery(PAccountDirectory.class);
Root<PAccountDirectory> root = query.from(PAccountDirectory.class);
From<?, PLDAPDirectory> ldap = cb.treat(root, PLDAPDirectory.class);
Predicate exp = cb.or(cb.equal(root.get( "active" ), true ),
cb.equal(ldap.get( "openldap" ), true ));
entityManager.createQuery(query.select(root).where(exp)).getResultList();
(
https://hibernate.atlassian.net/browse/HHH-15726#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15726#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:9b34d7c )