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: why ClassCastException when using session.createQuery(hql)?
PostPosted: Sun Jun 05, 2005 9:38 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.3

Code between sessionFactory.openSession() and session.close():


InventoryTransDetailsInfo info1 = (InventoryTransDetailsInfo)itdInfo;
if(info1.getActualitdDate() != null){
hql.append("select info.itemCode, info.fieldone, info.fieldtwo, info.fieldthree, info.fieldfour, sum(info.actualquantity) from InventoryTransDetailsInfo info").
append(" where ").
append("info.actualitdDate >= '").append(info1.getActualitdDate()).append("'").
append(" group by info.itemCode, info.fieldone, info.fieldtwo, info.fieldthree, info.fieldfour");

Query q=session.createQuery(hql.toString());
list = (List) q.list();

Full stack trace of any exception that occurs:

1506196 [http-8080-Processor21] INFO com.vertical - [InventoryTransWM.findforr
eport2()] START
q.getClass()in java---------------------->org.hibernate.impl.QueryImpl
Hibernate: select inventoryt0_.item_code as col_0_0_, inventoryt0_.field_1 as co
l_1_0_, inventoryt0_.field_2 as col_2_0_, inventoryt0_.field_3 as col_3_0_, inve
ntoryt0_.field_4 as col_4_0_, sum(inventoryt0_.actual_quantity) as col_5_0_ from
inventory_transaction_details inventoryt0_ where inventoryt0_.actual_itd_date>=
'Tue Mar 16 00:00:00 IST 2004' group by inventoryt0_.item_code , inventoryt0_.fi
eld_1 , inventoryt0_.field_2 , inventoryt0_.field_3 , inventoryt0_.field_4
list.size()in java---------------------->class java.util.ArrayList
list.getClass()in java---------------------->[Ljava.lang.Object;
1506346 [http-8080-Processor21] INFO com.vertical - [InventoryTransWM.findforr
eport2()] END
list.size() in JSP---------------------->3
list.getClass() in JSP---------------------->java.util.ArrayList
list.get(i)---------->[Ljava.lang.Object;@17d6c1

Name and version of the database you are using:
PostgreSQL


This is my code in JSP
InventoryTransDetailsInfo itdInfo = new InventoryTransDetailsInfo();
InventoryTransWM itwm = new InventoryTransWM();
ArrayList list = new ArrayList();
itdInfo.setActualitdDate(SActualitdDate.equals("") ? null : DateUtils.getDate(SActualitdDate));
itdInfo.setActualitdDateTo(SActualitdDateTo.equals("") ? null : DateUtils.getDate(SActualitdDateTo));


list = (ArrayList) itwm.findforreport2(itdInfo);

InventoryTransDetailsInfo info = null;
for (int i = 0; i < list.size(); i++) {
info = (InventoryTransDetailsInfo) list.get(i); // java.lang.ClassCastException at this line.

can i do this in Criteria if so guide me

I want to use group by in Criteria ?

Guide me friends?

[/b]

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 10:28 am 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
your query is Scalar Query (use SUM Aggregate function), return array (Object[] ) , not InventoryTransDetailsInfo.
see http://www.hibernate.org/hib_docs/reference/en/html_single/#manipulatingdata-scalarqueries and
http://www.hibernate.org/hib_docs/reference/en/html_single/#queryhql-aggregation


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 2:37 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
what should i use for group by in Criteria?

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 2:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
http://www.hibernate.org/hib_docs/v3/re ... projection


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.