java – MyBatis将属性映射到错误的枚举
我的域类具有映射到枚举的属性.奇怪的是MyBatis 3.4.x(3.4.0和3.4.4.这适用于3.3.x),Spring MyBatis 1.3.1试图用不相关的enum映射它并给出错误.
我的域类看起来像这样: public class OrderLine { private Long id; private Product product; private ProgrammedStatus programmedStatus; private String programmedFeedback; private boolean completed = false; } ProgrammedStatus是一个简单的枚举 public enum ProgrammedStatus { yes,no,error; } 正是这个编程的状态映射到编程列,如下所示, <resultMap id="orderLineResult" type="foo.OrderLine"> <id property="id" column="technical_order_line_id" /> <result property="programmedStatus" column="order_line_programmed" typeHandler="org.apache.ibatis.type.EnumTypeHandler" /> <result property="programmedFeedback" column="order_line_programmed_feedback" /> <result property="completed" column="order_line_completed" javaType="java.lang.Boolean" typeHandler="org.apache.ibatis.type.BooleanTypeHandler" /> <association property="product" notNullColumn="order_line_product_id" resultMap="foo.repository.mapper.ProductMapper.productResult" /> </resultMap> 我甚至尝试使用typeHandler映射javaType,但MyBatis似乎忽略了它. 很少有可能有用的信息, > UnrelatedEnum也是一个简单的Enum as ProgrammedStatus 我在其他代码处也发现了这个问题.我可以在这里使用我自己的特定typeHandler而不是EnumTypeHandler.问题是这个枚举匹配在我的程序中的很多地方使用,并且迁移机智3.4使我的程序不稳定. 解决方法
删除明确提到的枚举typeHandler对我有用
<resultMap id="orderLineResult" type="foo.OrderLine"> <id property="id" column="technical_order_line_id" /> <result property="programmedStatus" column="order_line_programmed" /> <result property="programmedFeedback" column="order_line_programmed_feedback" /> <result property="completed" column="order_line_completed" javaType="java.lang.Boolean" typeHandler="org.apache.ibatis.type.BooleanTypeHandler" /> <association property="product" notNullColumn="order_line_product_id" resultMap="foo.repository.mapper.ProductMapper.productResult" /> </resultMap> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |