Matteo Di Furia wrote: <insert id="mtquery_insert_key_retrieve" parameterClass="com.mt.db.generated.model.FotoSezione"> insert into foto_sezione (FOTO_SEZIONE_NOME, FOTO_SEZIONE_DESCRIZIONE, FOTO_SEZIONE_TIPO, FOTO_SEZIONE_DATA) values (#fotoSezioneNome:VARCHAR#, #fotoSezioneDescrizione:VARCHAR#, #fotoSezioneTipo:INTEGER#, #fotoSezioneData:DATE#) <selectKey keyProperty="fotoSezioneId" resultClass="int"> SELECT LAST_INSERT_ID() AS fotoSezioneId </selectKey> </insert> hi, I have same problem. I've resolved changing position in tag <insert> between query text and tag <selectKey>. It's strange for me but it works