You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Leonardo Kenji Shikida <sh...@gmail.com> on 2005/12/07 18:50:35 UTC
mysql autoincrement zero value
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
Re: mysql autoincrement zero value
Posted by Leonardo Kenji Shikida <sh...@gmail.com>.
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 <lm...@apache.org> wrote:
> Why are you inserting into an auto_increment field?
>
> Larry
>
>
> On 12/7/05, Leonardo Kenji Shikida <sh...@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
Re: mysql autoincrement zero value
Posted by Larry Meadors <lm...@apache.org>.
Why are you inserting into an auto_increment field?
Larry
On 12/7/05, Leonardo Kenji Shikida <sh...@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
>