[beanutils] Issue with RowSetDynaClass and oracle10g drivers...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[beanutils] Issue with RowSetDynaClass and oracle10g drivers...

Grégory Joseph
Hi list,

What I'm going to point out here is obviously an oracle issue, but I'd
like to see if someone's got a sensible workaround or solution to
this, considering I'm using beanutils' RowSetDynaClass.
I've got this piece of code (deliberately skipping imports and
exception handling for the purpose of readability here)
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection conn = DriverManager.getConnection(url, user, pass);
           
            String query = " SELECT some_date_field AS foo FROM
some_table WHERE id=?";
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setString(1, "T32000171");
            stmt.setMaxRows(200);
            rs = stmt.executeQuery();
           
            RowSetDynaClass result = new RowSetDynaClass(rs);
           
            System.out.println(result);

When I run this with oracle10g and latest drivers (ojdbc14 version
10.1.0.4 I believe), I get
org.apache.commons.beanutils.ConversionException: Cannot assign value of
type 'java.sql.Date' to property 'foo' of type 'java.sql.Timestamp'

If you need explanations, do this:
            rs.next();
            System.out.println("from resultset : " +
rs.getObject("month").getClass().getName());
            System.out.println("from metadata : " +
rs.getMetaData().getColumnClassName(1));

As you'd see if you'd try this out, the metadata says the column is of
type java.sql.Timestamp, while the resultset says it's a java.sql.Date
!

Seems oracle guys think that because that behaviour is documented, it
is fine: http://forums.oracle.com/forums/thread.jsp?forum=99&thread=300473&tstart=105&trange=15

Would a Converter help us, maybe?

We've also tried using functions like to_timestamp in the queries, but
that only makes things worse because, while the returned type is at
least consistent between resultset and metadata, it returns objects of
type oracle.TIMESTAMP which are just plainly oracle specific classes,
not implementations or subclasses of any java.sql types...

Any hint or info appreciated ! Thanks,

greg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] Issue with RowSetDynaClass and oracle10g drivers...

Simon Kitching
On Tue, 2005-06-14 at 15:20 +0200, Gr?gory Joseph wrote:

> When I run this with oracle10g and latest drivers (ojdbc14 version
> 10.1.0.4 I believe), I get
> org.apache.commons.beanutils.ConversionException: Cannot assign value of
> type 'java.sql.Date' to property 'foo' of type 'java.sql.Timestamp'
>
> If you need explanations, do this:
>             rs.next();
>             System.out.println("from resultset : " +
> rs.getObject("month").getClass().getName());
>             System.out.println("from metadata : " +
> rs.getMetaData().getColumnClassName(1));
>
> As you'd see if you'd try this out, the metadata says the column is of
> type java.sql.Timestamp, while the resultset says it's a java.sql.Date
> !
>
> Seems oracle guys think that because that behaviour is documented, it
> is fine: http://forums.oracle.com/forums/thread.jsp?forum=99&thread=300473&tstart=105&trange=15
>
> Would a Converter help us, maybe?

Method BasicDynaBean.set is the one throwing this exception. And it
doesn't use converters, so a custom converter won't help.

I suggest you subclass RowSetDynaClass and override the copy method to
fudge the conversion.

Or maybe subclass BasicDynaBean and override the set method to handle
the problem, then subclass RowSetDynaClass and override createDynaBean
to return instances of your custom bean that handles broken Oracle
resultsets.

Of course if Oracle would fix their broken software that would be a much
better solution...

Regards,

Simon



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [beanutils] Issue with RowSetDynaClass and oracle10g drivers...

Grégory Joseph
Thanks Simon. We got around to do something similar indeed... and I
agree with your statement about oracle ;-)

Cheers,

greg

On 15/06/05, Simon Kitching <[hidden email]> wrote:

> On Tue, 2005-06-14 at 15:20 +0200, Grégory Joseph wrote:
>
> > When I run this with oracle10g and latest drivers (ojdbc14 version
> > 10.1.0.4 I believe), I get
> > org.apache.commons.beanutils.ConversionException: Cannot assign value of
> > type 'java.sql.Date' to property 'foo' of type 'java.sql.Timestamp'
> >
> > If you need explanations, do this:
> >             rs.next();
> >             System.out.println("from resultset : " +
> > rs.getObject("month").getClass().getName());
> >             System.out.println("from metadata : " +
> > rs.getMetaData().getColumnClassName(1));
> >
> > As you'd see if you'd try this out, the metadata says the column is of
> > type java.sql.Timestamp, while the resultset says it's a java.sql.Date
> > !
> >
> > Seems oracle guys think that because that behaviour is documented, it
> > is fine: http://forums.oracle.com/forums/thread.jsp?forum=99&thread=300473&tstart=105&trange=15
> >
> > Would a Converter help us, maybe?
>
> Method BasicDynaBean.set is the one throwing this exception. And it
> doesn't use converters, so a custom converter won't help.
>
> I suggest you subclass RowSetDynaClass and override the copy method to
> fudge the conversion.
>
> Or maybe subclass BasicDynaBean and override the set method to handle
> the problem, then subclass RowSetDynaClass and override createDynaBean
> to return instances of your custom bean that handles broken Oracle
> resultsets.
>
> Of course if Oracle would fix their broken software that would be a much
> better solution...
>
> Regards,
>
> Simon
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]