Thanx Armin ,its class type is BigDecimal , and now its working fine when I cast it to BigDecimal. I got to know this when I did object[1].getClass() .
By the way armin , is there any rule which OJB follows for the "data type" of the the results of query in these type of cases , or do one has to rely on getClass() thing to do the right casting . Regards , Chandan -----Original Message----- From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 29, 2005 3:01 PM To: OJB Users List Subject: Re: Report query ClassCast exception . Chandan AHUJA wrote: > Hello Armin , > Thanx for your prompt help . > But the problem is not fully solved yet . > I am able to cast the return object of "iterator.next()" to an array > of object , its working fine . Also I am able to cast the first > element (Dept__id)of that array into (String) , its also working fine > . But the classcast exception comes when I try to cast the second > element of the object arrary (sum(age))into "Integer" . > > In my oracle database age is of type number . > In repository_user the jdbc_type of sge is INTEGER . > In class "Employee" age is of type Integer . > > Please let me know if I need to do some othere mapping also for the > sum(age). > hmm, maybe it's String or Long as said in previous post I don't know how 'sum' is mapped (Jakob is the query guru ;-)). So the only thing I can suggest is to search for the class type with a debugger or much simpler with System.err.println("type: " + result[1].getClass()); regards, Armin > Thanks and regards , > > Chandan . > PS : My code looks like this *********************** > Object result[] = (Object[])(iterator.next()); > System.err.println("casted successfully"); System.err.println("Size of > Result is " + result.length ); //This returns 2 > System.err.println( (String)result[0] ) ; //This works fine > > //The next casting fails > System.err.println( (Integer)result[1] ); ///This fails . > > ******************************************** > > > > -----Original Message----- > From: Armin Waibel [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 29, 2005 2:02 PM > To: OJB Users List > Subject: Re: Report query ClassCast exception . > > > Hi Chandan, > > Chandan AHUJA wrote: > >>Hello , >> I am very new to OJB .I have the following query . >> >> >>I am using the class "ReportQueryByCriteria" and am using some >>"group" functions in it . >> >> Eg . >> query = new ReportQueryByCriteria(Employee.class, criteria); >> query.setAttributes(new String[] { "dept__id" , "sum(age)" }); >> //dept__id is string , age is integer >> query.addGroupBy(new String[]{ "dept__id" }); >> iterator = broker.getReportQueryIteratorByQuery(query); >> >> >>Now please let me know when I do iterator.next() what should I cast >>the return object into . >>I have tried to cast it into (String) but it is not working and am getting >>classcast exception . >> >>The documentation of queries states following ....... >>"The ReportQuery returns an Iterator over a Collection of Object " >> >> >>Please explain me with a code snippet . >> > > > I would expect an object array: > > Object[] result = (Object[]) iterator.next(); > String deptId = (String) result[0]; > // I'm not sure sure how 'sum' will be mapped, maybe > // it's String too, but I expect Integer > Integer ageSum = (Integer) result[1]; > > regards, > Armin > > >>Thanks >> >>Chandan . >> >> >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
