Hello people,
BACKGROUND
I wrote an a Native SQL Query. This happens to be a SELECT query. Each of the returned columns has an alias using the AS keyword.
For example: SELECT f.id AS id, f.name AS name FROM foobar.
I also using scrolling, as supported by hibernate.
I am using scrolling in order to support paging. By paging, I mean retrieval of a set of rows, and then retrieval of the total number of rows. For example, if first is 0 and rows is 10, then the first ten rows are retrieved, then the total number of records is retrieved. If rows is 0, then that means retrieve all the rows.
My scrolling and paging do work, especially for HQL queries.
However, I noticed that when I use scrolling with Native SQL Queries, the AliasToBeanResultTransformer does not apply.
Just so that there is no confusing, my scroll code looks like this:
Code:
List<T> list = new ArrayList<T>();
ScrollableResults sr = query.scroll();
int matches = 0;
if (sr.first())
{
if (first >= 0)
{
int i = 0;
sr.scroll(first);
do
{
i++;
T a = (T) sr.get(0);
list.add(a);
if (sr.isLast())
{
break;
}
}
while (rows==0 && sr.next() || sr.next() && rows!=0 && i < rows);
}
sr.last();
matches = sr.getRowNumber();
}
When I use HQL, the line
T a = (T) sr.get(0); returns the transformed object. But when I use Native SQL, this does not happen.
QUESTION:
My question, with hibernate, how do you use native sql, scrolling, and result transformed objects? Is there a special trick to this that I am not aware of? I've debugged through the hibernate code, and my code, and the one critical line of code is this:
CustomLoader line 321 does not show any aliases. The constructor of CustomLoader does not assign any transformer aliases.
Thank you.