-->
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.  [ 5 posts ] 
Author Message
 Post subject: Return Type
PostPosted: Fri Mar 25, 2005 12:41 pm 
Newbie

Joined: Fri Mar 18, 2005 9:10 am
Posts: 6
I am executing the following named query, my return value will be a integer,

select count(*) from common.program where program_code = :macode and :saledate between program_start_date and program_end_date

what return type should i use to access the query result

Regards,
Vinay


Top
 Profile  
 
 Post subject: Re: Return Type
PostPosted: Sun Mar 27, 2005 4:23 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
What Java code /mapping docs exactly are you trying? The confusion might be between report queries and object queries... Chris

vinaypal wrote:
I am executing the following named query, my return value will be a integer,

select count(*) from common.program where program_code = :macode and :saledate between program_start_date and program_end_date

what return type should i use to access the query result

Regards,
Vinay


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 12:15 pm 
Newbie

Joined: Fri Mar 18, 2005 9:10 am
Posts: 6
Hibernate version:2.1.8

[b]Mapping documents:

Named Query

<sql-query name="NonJaguarEligibleStartAndEndDate">
select eligible_from,eligible_to from common.vehicle_eligible ve,
common.vehicle_year vy where vy.numeric_year = ve.model_year
and ve.program_code = :programCode
</sql-query>



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

Session s = getSession();
Query q = (Query)s.getNamedQuery
("NonJaguarEligibleStartAndEndDate");

q.setString("programCode", "100");
List retList = q2.list();
if (retList != null) {
System.out.println("NonJaguarEligibleStartAndEndDate size-- "
+ retList.size());
Object[] row = (Object[]) retList.get(10);
Date start = (Date) row[0];
Date end = (Date) row[1];
FOPPSession.logInfo(start.toLocaleString());

} else {
System.out.println("NULL");
}


/b]

[b] Exception:

NonJaguarEligibleStartAndEndDate -- 160
java.lang.ArrayIndexOutOfBoundsException: 0
at com.ma.fopp.service.dao.hibernate.FOPPValidatorHibernateDAO.getNonJaguarEligibleStartAndEndDates(FOPPValidatorHibernateDAO.java:269)
at com.ma.fopp.service.spring.FOPPValidatorServiceSpringImpl.validateVINSaleDate(FOPPValidatorServiceSpringImpl.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:284)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:163)
at $Proxy3.validateVINSaleDate(Unknown Source)
at com.ma.fopp.actions.validation.FOPPSaleDateValidateAction$FOPPSaleDateValidationThread.run(FOPPSaleDateValidateAction.java:194)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)




Name and version of the database you are using: Oracle 8i

The generated SQL (show_sql=true):

select eligible_from,eligible_to from common.vehicle_eligible ve, common.vehicle_year vy where vy.numeric_year = ve.model_year and ve.program_code = ?


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:40 pm 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
I dont really understand. In your first post, you have a count() query, in the code I dont see it. And what is the variable "q2". In any case, you are running report queries. I would like the type is Interger, though once you get hte Object array you can just do a row[0].getClass().getName() and find out (or debug and pause there). Right? Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:55 pm 
Newbie

Joined: Fri Mar 18, 2005 9:10 am
Posts: 6
Sorry for the confusion

If you look at my second post,

The query returns 160 object arrays, if I try to print the class name, i get an exception


Object[] row = (Object[]) list.get(0);
System.out.println( row[0].getClass().getName() )

java.lang.ArrayIndexOutOfBoundsException: 0


Regards,
Vinay


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