-->
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.  [ 3 posts ] 
Author Message
 Post subject: Native query, ScrollableResults and transformers
PostPosted: Fri May 27, 2011 5:04 am 
Newbie

Joined: Thu May 26, 2011 9:07 am
Posts: 4
Hi all,
I find myself in the following scenario:
we're porting a legacy system to J2EE and we choose to use JPA + HIBERNATE.
The legacy system had a persistence mechanism based on objects so it was quite
simple to translate most of the database interaction to @Entity class.
In some cases, it happened that sql queries were issued to load report data coming from
different tables or grouping results.
In those cases, a resultset was used and bean were populated using reflection thanks to
resultsetmetadata that provides information about how to map columns to bean properties.
Now, if I want to issue such a query (a native query I presume) and I want to load the result
in non entity classes how can I do that?
Searching the web, I found I can create an SQLQuery, set a aliasToBean transformer and than
list the result.
Anyway, since some of those queries were heavy and load huge resultset I was wondering whether is
possible to use a scrollableresults, it seems to fit perfectly what I need but...when I invoke scroll() on
an SQLQuery, the result I obtain fron the ScrollableResult for each row is an array of objects even if
the transformer is defined.
Is there anyway I can perform sql native query, obtaining a scrollable result and leaving the task to populate
non entity bean to hibernate?
thanks a lot
Fil


Top
 Profile  
 
 Post subject: Re: Native query, ScrollableResults and transformers
PostPosted: Fri May 27, 2011 8:48 am 
Newbie

Joined: Thu May 26, 2011 9:07 am
Posts: 4
Maybe I foud the solution, it was a bug!

http://opensource.atlassian.com/project ... e/HHH-3694

I switched to the new hibernate version and the aliasToBean transformer is
applied as desired :)


Top
 Profile  
 
 Post subject: Re: Native query, ScrollableResults and transformers
PostPosted: Fri May 27, 2011 1:01 pm 
Newbie

Joined: Thu May 26, 2011 9:07 am
Posts: 4
Ready for a new episode! :(
Switching to a recent version of hibernate (3.6.4), I was able to receive instances of the desired bean, invoking the scroll() method
on the SQLQuery object and navigating the ScrollableResults.
Anyway, those beans are empty!!
On the contrary, without changing anything else but using the list() method I objtained a list of desired bean with the properies set.
Debugging I noticed that issuing the list() method, the column aliases are calculated after the discovery phase and so the transformer is able to fill any bean, taking advantage of a populated list of column aliases.
On the contrary, when you invoke the scroll() method, the column aliases used by the trasformer are established before the autodiscovery phase and, since I don't provide any information on the query result, the aliases list is empty, so the transformer is not
able to set any property to each bean.
I'm going to check the last version, maybe it's a known issue and has benn fixed.
In the meanthime I opened a issue on JIRA
http://opensource.atlassian.com/project ... e/HHH-6270


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

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.