-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Native SQL Query with ResultTransform and scrolling.
PostPosted: Mon Oct 20, 2008 6:58 pm 
Newbie

Joined: Mon Oct 20, 2008 6:40 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.