[hibernate-issues] [JIRA] (HHH-14138) ScrollableResults closed unexpectedly when performing another query inside scroll loop

Jamie Strachan (JIRA) jira at hibernate.atlassian.net
Tue Aug 4 13:29:27 EDT 2020


Jamie Strachan ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f29960d5227f50014d306b2 ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDgwMWEyNDkyNDcyNDNmNjhlOTBhODUxN2Q4NmYxNmIiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiNDgwMWEyNDkyNDcyNDNmNjhlOTBhODUxN2Q4NmYxNmIiLCJwIjoiaiJ9 ) HHH-14138 ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiNDgwMWEyNDkyNDcyNDNmNjhlOTBhODUxN2Q4NmYxNmIiLCJwIjoiaiJ9 ) ScrollableResults closed unexpectedly when performing another query inside scroll loop ( https://hibernate.atlassian.net/browse/HHH-14138?atlOrigin=eyJpIjoiNDgwMWEyNDkyNDcyNDNmNjhlOTBhODUxN2Q4NmYxNmIiLCJwIjoiaiJ9 )

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=5f29960d5227f50014d306b2 )

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=eyJpIjoiNDgwMWEyNDkyNDcyNDNmNjhlOTBhODUxN2Q4NmYxNmIiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14138#add-comment?atlOrigin=eyJpIjoiNDgwMWEyNDkyNDcyNDNmNjhlOTBhODUxN2Q4NmYxNmIiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:8f92423 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200804/ed9fbfa1/attachment.html 


More information about the hibernate-issues mailing list