• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

return scalar result not able to display

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a native sql query in .hbm.sql, for that I have used <retrun column="colName" type="String"/>The query executed successfully and result come in a list with object. I am not able to take it from list as a string by typecasting or any otherway
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Hibernate reference can guide you on using native SQL with Hibernate. If the problem persists, please post your code and mappings.
 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had written following in hbm.xml

<sql-query name="FamilyHR.Hrafamilyid">
<return-scalar column="Question" type="string"/>
<return-scalar column="Answer" type="string"/>
<![CDATA[
select
question_list.qdesc as Question,
useranswers.ans_str as Answer
from
useranswers,

question_list
where
useranswers.qcode = question_list.qcode

]]>
</sql-query>

If I return only on one <return scalar> then in list I able to receive list with string , and able to display,
But if I return two <return scalar> then list contains objects and I not able to type cast that object, and on display
following message comming "[Ljava.lang.Object;@18b818b8
[Ljava.lang.Object;@1af41af4"
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is how you retrieve the query results. In case of more than one column or scalar returned, the type is Object[] (an array of Object).
 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Edvins,

Your reference helped me lot. I am now able to find the string ,sample code I have used given below

List question = new ArrayList();
Iterator itr= messFamily.iterator();
while(itr.hasNext()){
Object [] tuple =(Object []) itr.next();
String tmp = tuple[0].toString();
String tmp1 = tuple[1].toString();

question.add(tmp);
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic