<table tableName="%">
<generatedKey column="id" sqlStatement="MySql"/>
</table>
<table tableName="%">
<generatedKey sqlStatement="MySql"/>
</table>
El 24/04/2012 07:13, "Bogdan Tanase" <bfta...@gmail.com> escribió:
>
> Hi Javier,
>
> For autoincrement I use this:
>
> <generatedKey column="id" sqlStatement="JDBC"/>
This seems much cleaner than the other option (which is more specific) and I suppose the JDBC can be doing stuff under the interface call to the function.
>
> and the autoincremented value is received from the driver. Works fine with MySQL.
>
> upon insert the generated id is assigned to the id property of your pojo. Example:
>
> Order order = new Order();
> // ...
> // before insert order.id is null
> mapper.insert(order);
>
> // at this point order.id has the generated autoincrement value
>
> If you don't use generatedKey, inserts should work fine, but the id property of your pojo won't be populated on insert. It won't generate in your mapper insert tag useGeneratedKeys="true" attribute.
>
> I hope it helps, I didn't had my coffee yet :)
>
And about making all autoincrementable columns to use it?
<table name="%">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
then the generator will assume that ALL tables have an "id" column
that is auto increment. If that is your situation, then it will work.
Otherwise you will need to specify the generatedKey value correctly
for each table.
Jeff Butler