-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to store the result in bean class through hbm.xml file?
PostPosted: Fri Feb 29, 2008 2:22 am 
Newbie

Joined: Wed Feb 20, 2008 3:34 am
Posts: 9
Location: Bangalore
Guys,
Can any one of you help me to find the way for assigning the db result into bean class through hbm.xml file?

I am executing the stored procedure and getting result in DAO class. Then the result is assigned into the properties of one bean class through the setter methods.

DAO Code:

List apsList = query.list();
APSReportVO vo = new APSReportVO();
List apsReport = new ArrayList();

Code:
for(int i=0;i<apsList.size();i++) {
   String data = apsList.get(i).toString();
   if(data != null) {
      data = data.substring(1, data.length()-1);
      // data --->> [Lon, 014, 130]
      StringTokenizer token = new StringTokenizer(data, ",");
      vo.setBranchCode(token.nextToken());
      vo.setSourceSystemID(token.nextToken());
      vo.setTransactionID(token.nextToken());
      apsReport.add(record);
   }
}


Here i am getting the column values from every record using StringTokenizer and assigning into vo.

How to assign the column values to bean properties through hbm.xml file?

So we can avoid the following code in DAO class.

Code:
StringTokenizer token = new StringTokenizer(data, ",");
vo.setBranchCode(token.nextToken());
vo.setSourceSystemID(token.nextToken());
vo.setTransactionID(token.nextToken());
apsReport.add(record);


Can any one of you help me to find the way for this issue?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 3:24 am 
Newbie

Joined: Tue Dec 11, 2007 12:28 am
Posts: 5
The way u r trying to assign values retrieved from the db to ur VO is non-hibernatic.

Converting the result set List into strings and assigning ........ nooo !!

Map ur VO in the hbm.xml file to the corresponding table, mapping the properties of the VO to the columns of the table....

http://www.hibernate.org/hib_docs/reference/en/html/tutorial.html#tutorial-associations gives u a detailed description of mapping a pojo in a hbm.

then ur "query.list()" returns a List<VO> which will already be set with the values retrieved from the database.

try printing them and check..

If i've understood ur question correctly, this is the answer.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 6:49 am 
Newbie

Joined: Wed Feb 20, 2008 3:34 am
Posts: 9
Location: Bangalore
Thanks for the reply.
I changed my hbm.xml file given below. While executing the query.list(), it is not returning VOs as you mentioned. It is returning java.util.Arrays$ArrayList which I got already. Is there any change in hbm.xml file?


hbm.xml:
Code:
<hibernate-mapping>
     <class name="com.citi.aps.daovo.APSReportVO" table="ctsi_req_res_table">
         <id name="pmtRefID" column="PMT_REFERRENCE_ID">
             <generator class="native"/>
         </id>
         <property name="transactionID"/>
         <property name="sourceSystemID"/>
         <property name="debitAccount"/>
         <property name="orderInstitutBIC"/>
         <property name="creditAccount"/>
         <property name="accWithInstitutBIC"/>
         <property name="currency"/>
         <property name="valueDate"/>
         <property name="executionDate"/>
         <property name="postingStatus"/>
     </class>

     <sql-query name="APSReportForPayment" callable="true">
          { call p_get_APS_payment_report(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
     </sql-query>
 
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 29, 2008 7:01 am 
Newbie

Joined: Tue Dec 11, 2007 12:28 am
Posts: 5
query.list() will return a List<VO>. try iterating the list and check the Object that comes out of iterator.next() "instanceOf" ur VO. then typecast it to your VO and operate on it.

** You can use generics to avoid iterators and typecasting.. **


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.