【发布时间】:2018-01-19 11:16:23
【问题描述】:
我曾尝试通过 spring-data-jpa 使用 @Convert,但出现错误,这是我的代码:
entity
@Convert(converter = ListExtendConverterJson.class)
private List<Long> receivers;
ListExtendConverterJson implements AttributeConverter<List<Long>, String>:
@Override
public String convertToDatabaseColumn(List<Long> list) {
String result = JSONArray.toJSONString(list);
return result;
}
@Override
public List<Long> convertToEntityAttribute(String s) {
List<Long> result = JSONArray.parseArray(s, Long.class);
return result;
}
这是错误信息:
Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.List
at com.qf.posp.pub.config.entity.json.ListExtendConverterJson.convertToDatabaseColumn(ListExtendConverterJson.java:23)
at org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$1.bind(AttributeConverterSqlTypeDescriptorAdapter.java:78)
... 78 common frames omitted
那么有什么问题呢?
【问题讨论】:
-
也许this 的帖子会有用..
标签: mysql json spring-data-jpa type-conversion