I’m using MySQL 5.5.46
with MyBatis 3.3
and Spring 4.2
. I have a table with a primary key column that is of type VARCHAR(32)
. In my mapping file, I have this statement. Notice that I use MySql’s uuid()
to auto-generate an ID. How do I then take this ID and populate it in the returned object? I’m trying LAST_INSERT_ID()
but that isn’t doing it …
<insert id="insertMyObject" parameterType="org.mainco.myproject.domain.MyObject" keyProperty="id" keyColumn="id">
insert into cb_myproject_sync_entity_link(id, links_self, links_schools, links_teachers, links_students, links_sections, links_grade_levels, links_contacts)
values(replace(uuid(), '-', ''),#{linksSelf}, #{linksSchools}, #{linksTeachers}, #{linksStudents}, #{linksSections}, #{linksGradeLevels}, #{linksContacts})
<selectKey keyProperty="id" resultType="String" order="AFTER">SELECT LAST_INSERT_ID();</selectKey>
</insert>