Issue with String types when hibernate returns list of Object arrays
Bhanu S Chatta
Greenhorn
Joined: Apr 15, 2006
Posts: 19
posted
0
Hi,
I am seeing a wierd issue. My query is retuning the list of obejct arrays; which is fine. However for string type cloumns, it's retuning only the first character.
forexample: if the value in the column is 'bhanu', it's just retreving 'b'.
During the debug when I watch the retuned list; I see that field as Character Object. I am using Db2 database. Can someone explain me the reason for this issue?
And also can we have two bean classes map to one table? i.e.; can I write two hbm xml files for same table but each one map to different bean? May be foolish question. But appreciate the response...
thank you,
bhanu
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
You're probably not attaching the Java object to the query, but without seeing the query, it's tough to help.
Bhanu S Chatta
Greenhorn
Joined: Apr 15, 2006
Posts: 19
posted
0
Hi David,
Thank you for responding to my question.
Here is the query:
<sql-query name="bhanu >
<![CDATA[
select status, unit, dr_amount, cr_amount, cr_itm_cnt, dr_itm_cnt, aprvid1, aprvid2, comment
from transaction where trasaction_id= ? AND updt_by_ts < ?
ORDER BY trasaction_id ASC, updt_by_ts DESC
FOR READ ONLY
]]>
</sql-query>
In the above query - status,unit, aprvid1, aprvid2,comment are string fields. If I execute the query against the database for above fileds correct data is coming out...
but when I execute the query through the hibernate code, I get only the first character ...
Executing the query in the as below:
public List getTransactions(String trannum, Date date){
List tranlist=new ArrayList();
Query query = getSession().getNamedQuery("bhanu");
query.setLong(0, new Long(trannum));
query.setTimestamp(1, date);
tranlist=query.list();
}
Can you be more clear what do you mean by "attaching the Java object to the query"?
Please help me understand why that's happening...
thank you,
bhanu
>
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.
You can edit your post by using the button.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
If Hibernate doesn't know what type to associate with the query it'll return a list of Objects.
subject: Issue with String types when hibernate returns list of Object arrays