Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return scalar result not able to display

 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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);
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic