Reputation: 1573
So I got MyBatis inheritance working with annotations - child inherited @Select
functionality.
But with XML files it's not working accordingly.
It will throw:
org.apache.ibatis.binding.BindingException: Invalid bound statement /.../
Saw that some used extends
on the mapper
element, but for me it says "Attribute extends not allowed here"
Tried <cache/>
on parent and <cache-ref namespace="parent"/>
on child but that threw org.apache.ibatis.builder.IncompleteElementException: No cache for namespace 'parent'
So how to get MyBatis inheritance working with XML configuration?
Upvotes: 1
Views: 3263
Reputation:
I agree whit balckwizzard cache and cache-ref are not useful in this case (I have read too somewhere a post that suggest to use they to extend xml but I think that the post war an error)
I have put an answer that I think is good for you too:
Mybatis Generator: What's the best way to separate out “auto generated” and “hand edited files”
regards
Upvotes: 0
Reputation: 2044
Attribute extends applies to resultMap only.
cache and cache-ref are about cache management.
All what may look like extending is actually factorizing: define sql fragments in a XML mapper and reference them in other mappers. E.g:
-Mapper1.xml:
<sql id="a">/* dummy will never actually been included */</sql>
<sql id="b"> something common to include </sql>
<sql id="template">
<include refid="a" />
<include refid="Mapper1.b" />
</sql>
-Mapper2.xml
<sql id="a"> something specific to this mapper </sql>
<select id="statement">
<include refid="Mapper1.template" />
</select>
include tag behaves just like copy/paste of referenced fragments. Then the select statement will yield:
something specific to this mapper
something common to include
The trick is to play with prefixing or not referenced fragments. It may look like overriding.
Upvotes: 1