ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leonardo Kenji Shikida <shik...@gmail.com>
Subject Re: mysql autoincrement zero value
Date Wed, 07 Dec 2005 18:20:14 GMT
I discovered this by accident, during unit tests. I needed an expected
value and then I was inserting into it with specific values.

In fact, I was wondering if a little bit of reflection like

    public Object insert(Object o) throws SQLException{
        return this.dbclient.insert("insert"+o.getClass().getSimpleName(),o);
    }

could make my life easier. But it seems it won't be a good idea

in fact, it's worse than I thought

      1) inserting an object with id explicitly equal zero will make
         mysql create a new object with the next autoincrement value
         and will simply ignore all the other column values. Silently

      2) inserting an object with another explicitly non-zero id value
         will fail the query ibatis uses to get the next generated id
         (basically because no id was generated) and will return zero

good bye reflection :(

On 12/7/05, Larry Meadors <lmeadors@apache.org> wrote:
> Why are you inserting into an auto_increment field?
>
> Larry
>
>
> On 12/7/05, Leonardo Kenji Shikida <shikida@gmail.com> wrote:
> > if I try to insert an object with id=0 into a mysql table that have an
> > autoincrement id column, strange things happens
> >
> > mysql silently inserts that object with messy values. very dangerous.
> >
> > is there any workaround for this in mysql or ibatis? or will I have to
> > check explictly for zeroed ids and throw an exception?
> >
> > []
> >
> > Kenji
> > _______________________
> > http://kenjiria.blogspot.com
> > http://gaitabh.blogspot.com
> >
>


--

[]

Kenji
_______________________
http://kenjiria.blogspot.com
http://gaitabh.blogspot.com

Mime
View raw message