Jamie Strachan (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDgwMWEyNDky...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiNDgwMW...
) HHH-14138 (
https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiNDgwMW...
) ScrollableResults closed unexpectedly when performing another query inside scroll loop (
https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiNDgwMW...
)
Issue Type: Bug Affects Versions: 5.4.18 Assignee: Unassigned Components: hibernate-core
Created: 04/Aug/2020 10:29 AM Environment: 5.4.18
CentOS 7, Fedora 30
OpenJDK 1.8.0
Postgres 11 Priority: Major Reporter: Jamie Strachan (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960...
)
Using a second query while scrolling causes the ScrollableResults to be closed.
Minimal example:
public static void main( String [] args)
{
EntityManager em = getEntityManager();
// Query to be used while scrolling. Can be Native or not,
// it doesn't seem to matter what the query is. ( I just wanted to keep it simple)
Query qExtra = em.createNativeQuery( "SELECT 1" );
Query q = em.createQuery( "SELECT row FROM User row" );
q.setMaxResults(10);
@SuppressWarnings( "rawtypes" )
org.hibernate.query.Query hibernateQuery = q.unwrap(org.hibernate.query.Query.class);
ScrollableResults sr = hibernateQuery.scroll();
while (sr.next())
{
// Comment this query out and function finishes normally
qExtra.getSingleResult();
}
em.close();
}
Perhaps I am not supposed to unwrap the JPA2 query like that?
WIth Hibernate 5.1.0 and the following code to obtain a ScrollableResults, the example
code works as expected:
org.hibernate.Query query =
((org.hibernate.jpa.internal.QueryImpl)q).getHibernateQuery();
ScrollableResults sr = query.scroll(ScrollMode.FORWARD_ONLY);
However, running 5.4.18, it does not appear to matter what query I issue inside the loop,
it will close the result set.
The resulting exception from 5.4.18:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could
not advance using next()
at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:70)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:105)
at Test.main(Test.java:???)
Caused by: java.sql.SQLException: You can't operate on a closed ResultSet!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:691)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100)
... 1 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:685)
... 2 more
Thanks for any help!
(
https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-14138#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#100141- sha1:8f92423 )