[JIRA] (HHH-16588) getResultStream() together with join fetch delivers wrong results
by Adrian Pauli (JIRA)
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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:84d3b45 )
2 years, 11 months
[JIRA] (HHH-16587) WARN [org.hib.met.int.MetadataContext] (JPA Startup Thread) HHH015011: Unable to locate static metamodel field :
by Martin Panzer (JIRA)
Martin Panzer ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8c2e... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNTM1Y2M2MzE4... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16587?atlOrigin=eyJpIjoiNTM1Y2... ) HHH-16587 ( https://hibernate.atlassian.net/browse/HHH-16587?atlOrigin=eyJpIjoiNTM1Y2... ) WARN [org.hib.met.int.MetadataContext] (JPA Startup Thread) HHH015011: Unable to locate static metamodel field : ( https://hibernate.atlassian.net/browse/HHH-16587?atlOrigin=eyJpIjoiNTM1Y2... )
Change By: Martin Panzer ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8c2e... )
h3. Describe the bug
I have the following field in my entity:
{noformat}[...]
public class Rule {
[...]
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "condition", columnDefinition = "json")
private Predicate condition;
[..]
}{noformat}
During quarkus startup I now get following warning:
{noformat}2023-05-05 11:36:39,583 WARN [org.hib.met.int.MetadataContext] (JPA Startup Thread) HHH015011: Unable to locate static metamodel field : com.activelogistics.wolf.webruleservice.rule.db.model.Rule_#condition; this may or may not indicate a problem with the static metamodel {noformat}
The metamodel is generated by following dependency:
{noformat} <dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>{noformat}
The field condition is indeed missing in the metamodel.
During the Q3 migration, I changed the field from this:
{noformat} @Type(type = "io.hypersistence.utils.hibernate.type.json.JsonNodeBinaryType")
@Column(name = "condition", columnDefinition = "json")
private Predicate condition;{noformat}
And the condition was included in the metamodel.
Could it be, that {{JdbcTypeCode}} is not respected by the metamodel generator and therefore the field not included?
h3. Expected behavior
_No response_
h3. Actual behavior
_No response_
h3. How to Reproduce?
Reproducer: see attachment
[orm-warning-json.zip|https://github.com/quarkusio/quarkus/files/11406031/...]
# mvn clean compile quarkus:dev install
# Warning is printed Now run the unit test {{JPAUnitTestCase}}
# 2023-05-11 13:29:09 WARN MetadataContext:711 - HHH015011: Unable to locate static metamodel field : org.hibernate.bugs.MyEntity_#condition; this may or may not indicate a problem with the static metamodel
h3. Output of {{uname -a}} or {{ver}}
MINGW64_NT-10.0-19045 NANBCHL9NG3 3.3.6-341.x86_64 2022-09-05 20:28 UTC x86_64 Msys
h3. Output of {{java -version}}
openjdk version "17.0.4" 2022-07-19 OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8) OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing)
h3. GraalVM version (if different from Java)
_No response_
h3. Quarkus version or git rev
3.0.2.Final
h3. Build tool (ie. output of {{mvnw --version}} or {{gradlew --version}})
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: C:\eclipse\tools\java\maven Java version: 17.0.4, vendor: Eclipse Adoptium, runtime: C:\eclipse\tools\java\17 Default locale: de_DE, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
h3. Additional information
_No response_
( https://hibernate.atlassian.net/browse/HHH-16587#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16587#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:84d3b45 )
2 years, 11 months
[JIRA] (HHH-16587) WARN [org.hib.met.int.MetadataContext] (JPA Startup Thread) HHH015011: Unable to locate static metamodel field :
by Martin Panzer (JIRA)
Martin Panzer ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8c2e... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNTU5MzViOWFk... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16587?atlOrigin=eyJpIjoiNTU5Mz... ) HHH-16587 ( https://hibernate.atlassian.net/browse/HHH-16587?atlOrigin=eyJpIjoiNTU5Mz... ) WARN [org.hib.met.int.MetadataContext] (JPA Startup Thread) HHH015011: Unable to locate static metamodel field : ( https://hibernate.atlassian.net/browse/HHH-16587?atlOrigin=eyJpIjoiNTU5Mz... )
Change By: Martin Panzer ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8c2e... )
h3. Describe the bug
I have the following field in my entity:
{noformat}[...]
public class Rule {
[...]
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "condition", columnDefinition = "json")
private Predicate condition;
[..]
}{noformat}
During quarkus startup I now get following warning:
{noformat}2023-05-05 11:36:39,583 WARN [org.hib.met.int.MetadataContext] (JPA Startup Thread) HHH015011: Unable to locate static metamodel field : com.activelogistics.wolf.webruleservice.rule.db.model.Rule_#condition; this may or may not indicate a problem with the static metamodel {noformat}
The metamodel is generated by following dependency:
{noformat} <dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>{noformat}
The field condition is indeed missing in the metamodel.
During the Q3 migration, I changed the field from this:
{noformat} @Type(type = "io.hypersistence.utils.hibernate.type.json.JsonNodeBinaryType")
@Column(name = "condition", columnDefinition = "json")
private Predicate condition;{noformat}
And the condition was included in the metamodel.
Could it be, that {{JdbcTypeCode}} is not respected by the metamodel generator and therefore the field not included?
h3. Expected behavior
_No response_
h3. Actual behavior
_No response_
h3. How to Reproduce?
Reproducer:
[orm-warning-json.zip|https://github.com/quarkusio/quarkus/files/11406031/...]
# mvn clean compile quarkus:dev
# Warning is printed
h3. Output of {{uname -a}} or {{ver}}
MINGW64_NT-10.0-19045 NANBCHL9NG3 3.3.6-341.x86_64 2022-09-05 20:28 UTC x86_64 Msys
h3. Output of {{java -version}}
openjdk version "17.0.4" 2022-07-19 OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8) OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing)
h3. GraalVM version (if different from Java)
_No response_
h3. Quarkus version or git rev
3.0.2.Final
h3. Build tool (ie. output of {{mvnw --version}} or {{gradlew --version}})
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: C:\eclipse\tools\java\maven Java version: 17.0.4, vendor: Eclipse Adoptium, runtime: C:\eclipse\tools\java\17 Default locale: de_DE, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
h3. Additional information
_No response_
( https://hibernate.atlassian.net/browse/HHH-16587#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16587#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:84d3b45 )
2 years, 11 months