Adrian Pauli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5eda31c...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzg4OTQ1ZmQy...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16588?atlOrigin=eyJpIjoiNzg4OT...
) HHH-16588 (
https://hibernate.atlassian.net/browse/HHH-16588?atlOrigin=eyJpIjoiNzg4OT...
) getResultStream() together with join fetch delivers wrong results (
https://hibernate.atlassian.net/browse/HHH-16588?atlOrigin=eyJpIjoiNzg4OT...
)
Issue Type: Bug Affects Versions: 6.2.1 Assignee: Unassigned Created: 11/May/2023 04:50 AM
Environment: Quarkus 3.0.2 together with hibernate 6.2.1 Priority: Major Reporter: Adrian
Pauli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5eda31c...
)
Using “join fetch” together with getResultStream delivers incomplete entities (multiplie
times) depending on the order of the db result rows.
*How to reproduce*
------------------
*Setup:*
Entites:
@Getter
@Setter
@Entity
@Table(name = "notification_list" )
@ToString
public class NotificationListEntity {
@Id
@Column(name = "id" )
private UUID id;
@Column(name = "name" )
private String name;
@OneToMany(mappedBy = "notificationList" )
private Set<RoomEntity> roomIds;
}
@Getter
@Setter
@Entity
@Table(name = "notification_list_room" )
@ToString
public class RoomEntity {
@Id
@Column(name = "room_id" )
UUID roomId;
@ManyToOne
@JoinColumn(name = "notification_list_id" )
@ToString.Exclude
NotificationListEntity notificationList;
}
Prefill the db with:
insert into notification_list (id, name ) values (
'99006f27-a59f-491f-b7f8-7e83b8fc02b0' , ' A ' );
insert into notification_list (id, name ) values (
'd5d3bbcc-1c00-4aa5-af80-4ecd2aedfb99' , 'B' );
insert into notification_list (id, name ) values (
'73af7a07-1a6b-4f65-b77f-ab1613e7849d' , ' C ' );
insert into notification_list_room (notification_list_id, room_id) values (
'99006f27-a59f-491f-b7f8-7e83b8fc02b0' ,
'8f2890bb-79ef-4b09-9f04-1d1a2024cfe1' );
insert into notification_list_room (notification_list_id, room_id) values (
'99006f27-a59f-491f-b7f8-7e83b8fc02b0' ,
'ec7f587d-13c7-4f1f-105d-312ee5d655e8' );
insert into notification_list_room (notification_list_id, room_id) values (
'd5d3bbcc-1c00-4aa5-af80-4ecd2aedfb99' ,
'31197476-222e-47ef-87e2-4f0fefb0b97a' );
insert into notification_list_room (notification_list_id, room_id) values (
'99006f27-a59f-491f-b7f8-7e83b8fc02b0' ,
'92b12b36-8c00-4951-10db-263facfcb214' );
insert into notification_list_room (notification_list_id, room_id) values (
'73af7a07-1a6b-4f65-b77f-ab1613e7849d' ,
'd3acc6a1-e223-421d-a135-4142f159d548' );
insert into notification_list_room (notification_list_id, room_id) values (
'99006f27-a59f-491f-b7f8-7e83b8fc02b0' ,
'b0b12a45-0e1b-4b0d-9fb1-fab948835605' );
insert into notification_list_room (notification_list_id, room_id) values (
'99006f27-a59f-491f-b7f8-7e83b8fc02b0' ,
'8be1d3b3-2f1d-48b2-9982-77814003ce97' );
insert into notification_list_room (notification_list_id, room_id) values (
'99006f27-a59f-491f-b7f8-7e83b8fc02b0' ,
'df2ba159-92b5-4e78-1008-b181e5406a91' );
Methods:
public List<NotificationListEntity> streamAll() {
return entityManager
.createQuery(
"""
SELECT nle FROM NotificationListEntity nle
JOIN fetch nle.roomIds
""",
NotificationListEntity.class)
.getResultStream();
}
public List<NotificationListEntity> listAll() {
return entityManager
.createQuery(
"""
SELECT nle FROM NotificationListEntity nle
JOIN fetch nle.roomIds
""",
NotificationListEntity.class)
.getResultList();
}
*Result:*
Calling the “listAll()” delivers correct entities:
NotificationListEntity(id=99006f27-a59f-491f-b7f8-7e83b8fc02b0, name=A,
roomIds=[RoomEntity(roomId=b0b12a45-0e1b-4b0d-9fb1-fab948835605),
RoomEntity(roomId=df2ba159-92b5-4e78-1008-b181e5406a91),
RoomEntity(roomId=8be1d3b3-2f1d-48b2-9982-77814003ce97),
RoomEntity(roomId=ec7f587d-13c7-4f1f-105d-312ee5d655e8),
RoomEntity(roomId=8f2890bb-79ef-4b09-9f04-1d1a2024cfe1),
RoomEntity(roomId=92b12b36-8c00-4951-10db-263facfcb214)])
NotificationListEntity(id=d5d3bbcc-1c00-4aa5-af80-4ecd2aedfb99, name=B,
roomIds=[RoomEntity(roomId=31197476-222e-47ef-87e2-4f0fefb0b97a)])
NotificationListEntity(id=73af7a07-1a6b-4f65-b77f-ab1613e7849d, name=C,
roomIds=[RoomEntity(roomId=d3acc6a1-e223-421d-a135-4142f159d548)])
Calling the “streamAll()” delivers wrong entities:
NotificationListEntity(id=99006f27-a59f-491f-b7f8-7e83b8fc02b0, name=A,
roomIds=[RoomEntity(roomId=8f2890bb-79ef-4b09-9f04-1d1a2024cfe1),
RoomEntity(roomId=ec7f587d-13c7-4f1f-105d-312ee5d655e8)])
NotificationListEntity(id=d5d3bbcc-1c00-4aa5-af80-4ecd2aedfb99, name=B,
roomIds=[RoomEntity(roomId=31197476-222e-47ef-87e2-4f0fefb0b97a)])
NotificationListEntity(id=99006f27-a59f-491f-b7f8-7e83b8fc02b0, name=A,
roomIds=[RoomEntity(roomId=8f2890bb-79ef-4b09-9f04-1d1a2024cfe1),
RoomEntity(roomId=ec7f587d-13c7-4f1f-105d-312ee5d655e8)])
NotificationListEntity(id=73af7a07-1a6b-4f65-b77f-ab1613e7849d, name=C,
roomIds=[RoomEntity(roomId=d3acc6a1-e223-421d-a135-4142f159d548)])
NotificationListEntity(id=99006f27-a59f-491f-b7f8-7e83b8fc02b0, name=A,
roomIds=[RoomEntity(roomId=8f2890bb-79ef-4b09-9f04-1d1a2024cfe1),
RoomEntity(roomId=ec7f587d-13c7-4f1f-105d-312ee5d655e8)])
When adding a “order by nle.id (
http://nle.id ) ” it also works correctly with the
steam.
So the getResultStream should somehow handle this correctly or warn that fetch is not
allowed.
(
https://hibernate.atlassian.net/browse/HHH-16588#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16588#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#100225- sha1:84d3b45 )