Hmm... What about modifying Boolean2IntFeild itself so it handles both:

    private static Byte B_TRUE = new Byte(1);

    public Object sqlToJava(Object source)
    {
        if (source instanceof Integer)
        {
            if (source.equals(I_TRUE))
            {
                return Boolean.TRUE;
            }
            else
            {
                return Boolean.FALSE;
            }
        }
        else if (source instanceof Byte)
        {
            if (source.equals(B_TRUE))
            {
                return Boolean.TRUE;
            }
            else
            {
                return Boolean.FALSE;
            }
        }
        else
        {
            return source;
        }
    }


Would the fact that it passes an Intger, not a Byte to jdbc be a problem ? i
dont think it will in most cases - eg. mysql i use tinyint when field type
is integer if i know it will only be small.  Anyway, i dont think this would
do any harm, and would save anyone else going through the pain of working
out what is going on!

Daniel.

> -----Original Message-----
> From: Thomas Dudziak [mailto:[EMAIL PROTECTED]
> Sent: 07 September 2005 09:45
> To: OJB Users List
> Subject: Re: Boolean2IntFieldConversion with TINYINT
>
>
> On 9/7/05, Daniel Perry <[EMAIL PROTECTED]> wrote:
>
> > The following works fine:
> >
> > /**
> >  * @ojb.field jdbc-type="INTEGER"
> >  *
> >
> conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2
> IntFieldCo
> > nversion"
> >  */
> > protected boolean deleted;
> >
> > But, if you use:
> >
> > @ojb.field jdbc-type="TINYINT"
> >
> > Then, xdoclet does as it should:
> >
> >     <field-descriptor
> >         name="deleted"
> >         column="deleted"
> >         jdbc-type="TINYINT"
> >
> conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2
> IntFieldCo
> > nversion"
> >     >
> >
> > And ojb dies (although i am kinda sympathetic as it is using
> Boolean2Int,
> > not Boolean2Tinyint!):
> >
> > [PersistentField] ERROR: while set field:
> > [try to set 'object value' in 'target object'
> > target obj class: com.netcase.pol.bo.User
> > target field name: deleted
> > target field type: boolean
> > target field declared in: com.netcase.pol.bo.BaseBO
> > object value class: java.lang.Byte
> > object value: 0
> > ]
> >
> > ...
> >
> > Caused by: java.lang.IllegalArgumentException
> >         at
> >
> sun.reflect.UnsafeBooleanFieldAccessorImpl.set(UnsafeBooleanFieldA
> ccessorImp
> > l.java:68)
> >         at java.lang.reflect.Field.set(Field.java:656)
> >         at
> >
> org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAc
> cessImplNe
> > w.setValueFor(PersistentFieldDirectAccessImplNew.java:213)
>
>
> Ah, ok, now it is clear. This has nothing to do with XDoclet at all,
> rather the conversion that you specified, is wrong because it converts
> between boolean/java.lang.Boolean and int/java.lang.Integer. The
> problem arises because the JDBC driver returns a java.lang.Byte object
> for the TINYINT column and not an java.lang.Integer object that the
> conversion expects.
> Therefore you'll have to either use BIT as the JDBC column type or
> write your own Boolean2Byte conversion (simply copy the code of the
> Boolean2Int conversion and replace Integer with Byte).
>
> Tom
>
> ---------------------------------------------------------------------
> 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]

Reply via email to