[英]Multiple assocations with same base mapper
我有一个基本的resultMap用于定义如下的版本信息:
<resultMap id="VersionedEntityMapper" type="org.chu.wit4h.db.AbstractVersionedEntity">
<result property="version" column="version"/>
<result property="lastModified" column="lastModified"/>
<result property="lastModifier" column="lastModifier"/>
</resultMap>
然后一些实体映射器扩展了它:
<resultMap id="Entity1Mapper" type="org.Entity1" extends="VersionedEntityMapper">
<result property="name" column="name" />
<result property="firstName" column="firstName" />
</resultMap>
<resultMap id="Entity2Mapper" type="org.Entity2" extends="VersionedEntityMapper">
<result property="room" column="room"/>
</resultMap>
一切正常,直到我做到了:
<resultMap id="Entity3Mapper" type="org.Entity3">
<id property="id" column="id" />
<association property="info" javaType="org.Entity1" resultMap="Entity1Mapper"/>
<association property="location" javaType="org.Entity2" resultMap="Entity2Mapper"/>
</resultMap>
因此,列名称版本,lastModified和lastModifier冲突。 我可以在SQL语句中为它们加上别名,但是如何将前缀传递给内部映射器?
为了使用现有的resultMap
映射关联的实体,您需要向结果中关联的实体的所有列添加一些前缀,并通过columnPrefix
属性指定该前缀。
在上面的例子中的字段Entity1
应该被命名为喜欢entity1_name, entity1_first_name, entity1_version
等在选择查询Entity3
。
映射应修改:
<resultMap id="Entity3Mapper" type="org.Entity3">
<id property="id" column="id" />
<association property="info" javaType="org.Entity1" resultMap="Entity1Mapper"
columnPrefix="entity1"/>
...
</resultMap>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.