-->
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: query.list() type casting
PostPosted: Wed Dec 22, 2010 1:04 am 
Newbie

Joined: Tue Dec 14, 2010 7:48 am
Posts: 10
Query q=getSession().createSQLQuery("select loan_dar.loan_account_id,loan_dar.transaction_date,loan_dar.due_date,loan_dar.principal_amount,loan_dar.interest_amount,loan_dar.penal_amount,loan_dar.dar_Flag,loan_dar.current_Due,loan_dar.installment_no,loan_dar.fc_entered_date,loan_dar.prin_balance,loan_dar.int_balance,loan_dar.prin_overdue,loan_dar.penal_overdue from loan_dar left outer join gl_txn_ledger_master on gl_txn_ledger_master.fc_gl_txn_id=loan_dar.gl_txn left outer join gl_txn_ledger_entry on gl_txn_ledger_entry.fc_gl_entry_id=loan_dar.principal_gl_entry and gl_txn_ledger_entry.fc_gl_entry_id=loan_dar.interest_gl_entry and gl_txn_ledger_entry.fc_gl_entry_id=loan_dar.penal_gl_entry left outer join user_table on user_table.fc_user_id=loan_dar.fc_user_id where loan_dar.loan_account_id='"+account+"' and loan_dar.dar_Flag='"+darflag+"' and loan_dar.transaction_date<'"+dueDate+"' ");

this is my query contains joins i scomplex........query is working fine

when query.list() returns many rows (may be returning object[])
when typecasting iam not able to type cast................please help me......


Top
 Profile  
 
 Post subject: Re: query.list() type casting
PostPosted: Wed Dec 22, 2010 2:38 am 
Newbie

Joined: Tue Dec 21, 2010 8:21 am
Posts: 5
i have already posted
we can typecast by using iterator and type caste the each object with corresponding getXXX() and setXXX() function
Regards


Top
 Profile  
 
 Post subject: Re: query.list() type casting
PostPosted: Wed Dec 22, 2010 3:14 am 
Newbie

Joined: Tue Dec 14, 2010 7:48 am
Posts: 10
thanks a lot.......


Top
 Profile  
 
 Post subject: Re: query.list() type casting
PostPosted: Wed Dec 22, 2010 6:22 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
If you map your objects properly you don't need to write such complex queries, but can load your objects directly, and let hibernate to all casts and conversions as needed.
BTW you should never concatenate Strings like you did, use query parameters.

And even if you need to write "native SQL" - sometimes it's just more practical - there are helpers to handle joins and list all properties:
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#d0e17349

_________________
Sanne
http://in.relation.to/


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.