Ibatis Sequence Number Generation

644 views Asked by At

I am new to Ibatis. How do I generate a sequence number using Ibatis and insert that number into a mysql table? The sequence number should start with 1000 so that it can be used as a primary key in the table. I am using spring, ibatis and mysql.

1

There are 1 answers

0
luboskrnac On

As iBatis is dead since 2010, I presume MyBatis usage. With MyBatis you can use these annotations to insert and retrieve primary key from DB and map both to a interface:

@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="call identity()", keyProperty="nameId", before=false, resultType=int.class)
int insertTable2(Name name);