I moved from Hibernate 5 to Hibernate 6 and stuck with very strange issue. when I create native query that should return multiple entities of same type it return only first one.
I use example from Hibernate documentation to test it so:
List<Object[]> res = sess.createSQLQuery("SELECT {cat.*}, {m.*} FROM CATS c, CATS m WHERE c.MOTHER_ID = m.ID")
.addEntity("cat", Cat.class)
.addEntity("mother", Cat.class)
.list()
In Hib 5 I get row with two different cats("cat" and "mother"), but in hib 6 its row with two same "cat" entity.
I tried to find any reference to this in Hibernate 6 documentation, but they removed this example and put another one with two different entitiy types. Example:
List<Object> entities = session.createNativeQuery(
"SELECT {pr.*}, {pt.*} " +
"FROM Person pr, Partner pt " +
"WHERE pr.name = pt.name", Object.class)
.addEntity("pr", Person.class)
.addEntity("pt", Partner.class)
.list();
It was a bug: https://hibernate.atlassian.net/browse/HHH-17605
Fix is available as of Hibernate 6.4.3