ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Balazs Fejes <fbal...@gmail.com>
Subject selectkey in MYSQL
Date Sun, 23 Jan 2005 14:26:02 GMT

I am trying to build an application using iBatis, and MySQL.
When I'm using an insert statement, and the ID of the row is generated
using the autoincrement feature of mysql, for some reason <selectkey>
still sets the attribute of the object (and returns with) 0.

Here's the insert statement:
  <insert id="insertShow" parameterClass="show">
      <selectKey resultClass="int" keyProperty="id">
    insert into shows ( title, coverimage )
    values ( #title#, #coverimage# )

The insert succeeds, the ID is properly generated for the row.
If I execute the same 2 statements (insert and then select
last_insert_id()) on the mysql console, it does return the proper last
generated ID.
But executing this test code:
    public void testInsertShow() {
        Show atlantis = new Show("SG Atlantis");
        int key = showsDao.insertShow(atlantis);
        System.out.println("id ="+atlantis.getId());

Shows that the Id attribute is set to 0. Also, the return value (key) is 0.
I did a search on the mailing list, and I haven't found any previous
record of this mysql feature yet, did anyone succeed to get this

Best regards,

View raw message