Using Auto Generate Mapper with MyBatis.

Case:
First time inserting a record, that inserted record ID needed for another transaction. Use this SQL:

<INSERT id = "insert" parameterType = "com.fikri.model.User"> 
<selectKey keyProperty = "id" resultType = "java.lang.Long" ORDER = "AFTER">
SELECT SEQ_USER.CURRVAL FROM DUAL 
</selectKey>........</INSERT>

 


Simplified version:

 

<INSERT id = "insert" parameterType = "com.fikri.model.User" useGeneratedKeys = "true" keyProperty = "id" keyColumn = "id" >........</INSERT>
Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Written by Fikri Akbarsyah Anza, M.Kom

Lecturer