Stephane Malbequi (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMTAzZDFmOTg0...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16488?atlOrigin=eyJpIjoiMTAzZD...
) HHH-16488 (
https://hibernate.atlassian.net/browse/HHH-16488?atlOrigin=eyJpIjoiMTAzZD...
) Hibernate ORM 6.2.1 / Wrong select clause generated / OneToOne between the same entity (
https://hibernate.atlassian.net/browse/HHH-16488?atlOrigin=eyJpIjoiMTAzZD...
)
Issue Type: Bug Affects Versions: 6.2.1 Assignee: Unassigned Attachments:
hibernate-test-case-bug-select-one2one-main.zip Created: 18/Apr/2023 07:17 AM Priority:
Major Reporter: Stephane Malbequi (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Hi,
The following code seems to generate an erroneous SQL query.
@Entity
public class Person {
@Id
private String id;
@OneToOne
private Person bestFriend;
public Person() {
}
public Person(String id, Person bestFriend) {
this.id = id;
this.bestFriend = bestFriend;
}
public String getId() {
return id;
}
}
@Test
public void wrong_select_generated() {
EntityManager entityManager = entityManagerFactory.createEntityManager();
Person friend = new Person("friend", null);
Person person = new Person("person", friend);
entityManager.persist(friend);
entityManager.persist(person);
entityManager.getTransaction().begin();
List<Object[]> results = entityManager.createQuery("""
select p.id, f.id
from Person p
left join p.bestFriend f
order by p.id desc
""", Object[].class)
.getResultList();
Assert.assertEquals(person.getId(), results.get(0)[0]);
Assert.assertEquals(friend.getId(), results.get(0)[1]);
entityManager.getTransaction().commit();
entityManager.close();
}
The unit test result is:
Expected :friend
Actual :person
The generated query is:
Hibernate:
select
p1_0.id
from
Person p1_0
order by
p1_0.id
The unit test passes with Hibernate 6.1.7.Final and the generated query is:
Hibernate:
select
p1_0.id,
p1_0.bestFriend_id
from
Person p1_0
order by
p1_0.id desc
(
https://hibernate.atlassian.net/browse/HHH-16488#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16488#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#100222- sha1:c08beee )