Jones (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWQyMmU4NmNm...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16397?atlOrigin=eyJpIjoiMWQyMm...
) HHH-16397 (
https://hibernate.atlassian.net/browse/HHH-16397?atlOrigin=eyJpIjoiMWQyMm...
) Wrong SQL when HQL has subquery using FK attribute (
https://hibernate.atlassian.net/browse/HHH-16397?atlOrigin=eyJpIjoiMWQyMm...
)
Change By: Jones (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Given
* Entity with @ManyToOne attribute
When
* Executing HQL with subquery using @ManyToOne attribute
Then
* Wrong query is generated and wrong results are returned
{code:java}@Entity
@Table(name = "ENTITY_A")
public class EntityA {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
Integer id;
@Column(name = "PROPERTY_A")
int propertyA;
@ManyToOne
@JoinColumn(name = "REFERENCE")
EntityA reference;
}{code}
{code:java} @Test
public void hhhXXXXTest() throws Exception {
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and
// provides the Session.
try (Session s = openSession()) {
Transaction tx = s.beginTransaction();
EntityA entityA1 = new EntityA();
s.persist(entityA1);
s.flush();
Query<EntityA> query = s.createQuery(
"select c from EntityA c where c.propertyA = (select max(e.propertyA) from EntityA e
where (c.reference is null and e.reference is null))",
EntityA.class);
List<EntityA> actual = query.list();
assertThat(actual).hasSize(1);
tx.commit();
}
}{code}
{noformat}Hibernate:
select
e1_0.ID,
e1_0.PROPERTY_A,
e1_0.REFERENCE
from
ENTITY_A e1_0
where
e1_0.PROPERTY_A=(
select
max(e2_0.PROPERTY_A)
from
ENTITY_A e2_0,
ENTITY_A r1_0
where
(
r1_0.ID is null
and e2_0.REFERENCE is null
)
and r1_0.ID=e1_0.REFERENCE
){noformat}
{noformat}java.lang.AssertionError:
Expected size:<1> but was:<0> in:
<[]>{noformat}
Failing test scenario to be attached and also available here
[
https://github.com/ratoaq2/HHH-16397|https://github.com/ratoaq2/HHH-16397...]
(
https://hibernate.atlassian.net/browse/HHH-16397#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16397#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#100219- sha1:6a6077b )