我的域类具有映射到枚举的属性。奇怪的是MyBatis 3.4.x(3.4.0和3.4.4。这适用于3.3.x),Spring MyBatis 1.3.1试图用不相关的enum映射它并给出错误。
org.mybatis.spring.MyBatisSystemException:嵌套异常是org.apache.ibatis.executor.result.ResultMapException:尝试从结果集中获取列'order_line_programmed'时出错。原因:java.lang.IllegalArgumentException:没有枚举常量foo.UnrelatedEnum.yes
我的域类看起来像这样:
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似乎忽略了它。
很少有可能有用的信息,
我在其他代码处也发现了这个问题。我可以在这里使用我自己的特定typeHandler而不是EnumTypeHandler。问题是这个枚举匹配在我的程序中的许多地方使用,并且迁移机智3.4使我的程序不稳定。
答案 0 :(得分:0)
删除明确提到的enum typeHandler为我工作
删除:typeHandler =&#34; org.apache.ibatis.type.EnumTypeHandler&#34;
<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>