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 <[EMAIL PROTECTED]> wrote:
> Why are you inserting into an auto_increment field?
>
> Larry
>
>
> On 12/7/05, Leonardo Kenji Shikida <[EMAIL PROTECTED]> 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