What does session.createQuery("Query").scroll() return ?
-
ListResultSet
-
ResultSet
-
ScrollableResultSet
-
ScrollableResult
To understand what session.createQuery("Query").scroll() returns, the user needs to know about Hibernate and its query methods.
Hibernate is an ORM (Object-Relational Mapping) library that provides an interface between Java classes and SQL databases. It provides several query methods to interact with the database, including session.createQuery().
session.createQuery("Query").scroll() method is used to iterate over a large number of objects without loading them all into memory at once. It returns a ScrollableResults object that can be used to scroll through the results one at a time.
Now, let's go through each option and explain why it is right or wrong:
A. ListResultSet: This option is incorrect because there is no such class as ListResultSet in Hibernate.
B. ResultSet: This option is incorrect because session.createQuery("Query").scroll() does not return a ResultSet object. Hibernate uses a different interface called ScrollableResults for scrolling through large datasets.
C. ScrollableResultSet: This option is incorrect because there is no such class as ScrollableResultSet in Hibernate.
D. ScrollableResult: This option is correct. session.createQuery("Query").scroll() returns a ScrollableResult object that can be used to scroll through the results one at a time.
Therefore, the answer is: D. ScrollableResult.
In Hibernate, calling scroll() on a Query returns an org.hibernate.ScrollableResults instance (a cursor-based, forward/backward navigable result), not a JDBC ResultSet or any 'ResultSet'-named type. The actual interface name is ScrollableResults (plural). Among the four options, 'ScrollableResult' (id 606940) is a singular misspelling of the real type but is unambiguously the intended and closest correct choice; the distractors 'ListResultSet', 'ResultSet', and 'ScrollableResultSet' are all incorrect. So the DB's marked answer is the best available option. The naming should be corrected to 'ScrollableResults' for accuracy, but the marking stands.