I am using MyBatis to do a large number of updates to a Postgresql database. Some of the objects I'm pushing to the database have combined key objects for their ids--a custom java object that represents two columns in the resulting table, the combination of which is guaranteed to be unique. I'm seeing poor performance for updating these objects (there are thousands of them) and have seen that having an id field marked in your resultMap can improve performance. However, I'm not sure what the right syntax is for marking an association as an id.
I currently have created the resultMap with all of the properties described EXCEPT for the id itself.
<resultMap id="result" type = "com.sms.MyClass">
<result....>
<association property="id" javaType="com.sms.CombinedKeyClass">
<constructor>
<arg column="idVal1" javaType="int"/>
<arg column="idVal2" javaType="int"/>
</constructor>
<result property="idVal1" column="idVal1"/>
<result property="idVal2" column="idVal2"/>
</association>
</resultMap>
I'm trying to figure out how to mark this association as the id for the resultMap. I tried adding the following:
<resultMap id="result" type = "com.sms.MyClass">
<id property="id" javaType="com.sms.CombinedKeyClass"/>
<result....>
<association property="id" javaType="com.sms.CombinedKeyClass">
<constructor>
<arg column="idVal1" javaType="int"/>
<arg column="idVal2" javaType="int"/>
</constructor>
<result property="idVal1" column="idVal1"/>
<result property="idVal2" column="idVal2"/>
</association>
</resultMap>
MyBatis yells at me when I try this configuration, saying that it doesn't have a typeHandler for "property id". Is there a way to refer to the association as the typeHandler for the id? Or is there a way to mark the association itself as the id for the resultMap?
Also, is any of this going to help my update performance in the first place? Right now I'm passing in a List of these objects and using a "foreach" for each item in the list to update the relevant fields. I'd assumed this would be faster than making a separate update call to MyBatis for each individual update, but so far it hasn't been.