[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6270) AliasToBeanResultTransformer behaves differenty if you call the list() or the scroll() method on an SQLQuery object

Filippo Machi (JIRA) noreply at atlassian.com
Fri May 27 12:52:24 EDT 2011


AliasToBeanResultTransformer behaves differenty if you call the list() or the scroll() method on an SQLQuery object
-------------------------------------------------------------------------------------------------------------------

                 Key: HHH-6270
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6270
             Project: Hibernate Core
          Issue Type: Bug
    Affects Versions: 3.6.4
         Environment: 3.6.4
postgres 9
            Reporter: Filippo Machi


Executing an sql query using the SQLQuery class, in particular using createSQLQuery(..) method and setting a transformer, in particular an AliasToBeanResultTransformer I noticed that the obtained beans are different if you use the scroll() or the list() method: using scroll() beans are not filled as expected.
Consider the following excerpts, the former uses the list() method the latter the scroll() one on the same SQLQuery object, nothing else changes.

----- LIST -----

SQLQuery query = session.createSQLQuery("select website, category, name, country,.....");
query.setResultTransformer(Transformers.aliasToBean(Crawler.class));
List<Crawler> result = query.list();
for(Crawler row:result) {
     System.out.println(row.toString());
}

----- SCROLL ----

SQLQueryImpl query = (SQLQueryImpl)session.createSQLQuery("select website, category, name, country,.....");
query.setResultTransformer(Transformers.aliasToBean(Crawler.class));
ScrollableResultsImpl result = (ScrollableResultsImpl) query.scroll();
while(result.next()) {
	Object[] obj = result.get();
        // in this case the object is an empty crawler class


}

Consider that the Crawler class isn't an entity and it holds values coming out from a complex query. 
Debugging I saw that performing a list(), in the CustomLoader, the HolderInstantiator object that wraps the result transformer and the column aliases it uses is built after the autodiscovery phase, so it take advantages of it, providing the right aliases (a filled list of column aliases) to the transformer. And in this case beans are succesfully filled.
On the contrary, invoking the scroll() method, the HolderInstantiator is built before accessing the result set
and the autodiscovery phase, so there are no aliases.
In this case the transformer is invoked without providing any column alias. 
These two behaviours are not coherent among each other to me.
		

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list