May I suggest that you simply dump the class to the stderr e.g. something
like this
Object tmp = result[1];
System.err.println( tmp == null ? " Null" : message.getClass().getName() +
" = " + String.valueOf(tmp));
This should show you what to cast to (as well as the value returned).
Tangent Follows....
By the way, by using ReportQueries you are basically relying on the JDBC
driver to determine what class of objects to return - which is why we can't
simply say "cast to a Integer/String/Number" - it depends upon the database
and JDBC driver.
In our application we have a simple helper class for report queries that
very simply does the casts internally, and deals with platform differences.
For example, on MS-SQL we create boolean columns as BIT datatypes whereas on
DB2 we use SMALLINT. The MS-SQL JDBC driver returns Boolean for one of our
boolean columns, wheras the DB2 driver returns an integer.
So, we do (well, pseudo code of something a bit like what do)
Boolean value = ReportQueryHelper.getBoolean(columns, 0);
...
ReportQueryHelper#getBoolean :
public static getBoolean(Object[] cols, int idxCol){
Object colValue = cols[idxCol];
if(colValue instance of Boolean){
return (Boolean) colValue
}
if(colValue instance of Number){
Number num = (Number) colValue;
return num.intValue()==0 ? Boolean.FALSE : Boolean.TRUE;
}
throw new IllegalArgumentException("Some Helpful Error Message Here");
}
Cheers,
Charles.
-----Original Message-----
From: Chandan AHUJA [mailto:[EMAIL PROTECTED]
Sent: 29 March 2005 10:20
To: 'OJB Users List'
Subject: RE: Report query ClassCast exception .
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).
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]
___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]