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.  [ 3 posts ] 
Author Message
 Post subject: Ljava.lang.Object; incompatible with com.<MyCustomObj>
PostPosted: Thu Jan 21, 2010 3:41 pm 
Newbie

Joined: Thu Jan 21, 2010 3:20 pm
Posts: 17
Hi ,

I am using HQL and needs to print my List of custom objects for debugging .
However it throws following error while casting Object to custom class.

Ljava.lang.Object; incompatible with com.mortgageBean

Find the code snippet below
1. DAO Code
Query query = session.getNamedQuery("getReport");
List mortbeanList = (List) query.list();
List downCastedMortBeanList = new ArrayList()
Iterator iterator = mortbeanList.iterator();

while (iterator.hasNext()) {
MortgageBean mortgageBean = (MortgageBean) iterator.next();
downCastedMortBeanList.add(mortgageBean);
}


2. hbm file
<query name="getReport

<![CDATA[
Select
mtg.mortgageNumber,
from
MortgageBean mtg
where
(1=:searchInd AND district = :district)
order by
mortgageNumber

]]>
</query>

Any pointers ...

Note: - I checked that there is " <return alias=" which could be help but that is available only for native queries [ <sql-query ].


Top
 Profile  
 
 Post subject: Re: Ljava.lang.Object; incompatible with com.<MyCustomObj>
PostPosted: Fri Jan 22, 2010 5:53 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I am not so familiar with named queries but in your query you are selecting only a single property:
Code:
Select mtg.mortgageNumber...


This is of course not a MortgageBean object. Instead try:
Code:
Select mtg ...


Top
 Profile  
 
 Post subject: Re: Ljava.lang.Object; incompatible with com.<MyCustomObj>
PostPosted: Fri Jan 22, 2010 12:11 pm 
Newbie

Joined: Thu Jan 21, 2010 3:20 pm
Posts: 17
Thanks nordborg . It works now.

Note: - It threw an intemittent error though that MORTGAGE_.VAR2 IS NOT VALID IN THE CONTEXT WHERE IT IS USED. I missed declaring this variable as @transient in the annotated class. After this change it worked fine.


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