Jean-Francois Fournier (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOWYzYTIyMmRi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16492?atlOrigin=eyJpIjoiOWYzYT...
) HHH-16492 (
https://hibernate.atlassian.net/browse/HHH-16492?atlOrigin=eyJpIjoiOWYzYT...
) Hibernate 6 does not auto flush when calling Query.stream() (
https://hibernate.atlassian.net/browse/HHH-16492?atlOrigin=eyJpIjoiOWYzYT...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: hibernate-core
Created: 19/Apr/2023 04:29 AM Environment: Hibernate 6.1.7
Java 17
Oracle Sql Priority: Major Reporter: Jean-Francois Fournier (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Calling query.stream() doesn’t auto flush the persistence context. Calling query.list()
does flush the persistence context. This seems to be a bug as it was working with both
methods in hibernate 5.
If we use the exemple found in
https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_...
assertTrue((( Number ) entityManager
.createNativeQuery( "select count(*) from Person" )
.getSingleResult()).intValue() == 0);
Person person = new Person( "John Doe" );
entityManager.persist(person);
assertTrue((( Number ) entityManager
.createNativeQuery( "select count(*) from Person" )
.getSingleResult()).intValue() == 1);
And tweak it a bit to use stream(), it won’t work. (but works in hibernate 5)
assertTrue(entityManager
.createNativeQuery( "select name from Person where name = 'John Doe' "
)
.getResultList().size() == 0);
Person person = new Person( "John Doe" );
entityManager.persist(person);
assertTrue(entityManager
.createNativeQuery( "select name from Person where name = 'John Doe' "
)
.getResultStream().toList().size() == 1);
But it works if it uses list() instead
assertTrue(entityManager
.createNativeQuery( "select name from Person where name = 'John Doe' "
)
.getResultList().size() == 0);
Person person = new Person( "John Doe" );
entityManager.persist(person);
assertTrue(entityManager
.createNativeQuery( "select name from Person where name = 'John Doe' "
)
.getResultList().size() == 1);
I look into the source a bit and AbstractSelectionQuery. stream() doesn’t call
beforeQuery(); like AbstractSelectionQuery.list() do. So NativeQueryImpl.
prepareForExecution() is never called when using stream().
Thank you
(
https://hibernate.atlassian.net/browse/HHH-16492#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16492#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:cb3bdf0 )