NutzCN Logo
问答 java类型映射数据库类型问题
发布于 1699天前 作者 Zhouwt998 1335 次浏览 复制 上一个帖子 下一个帖子
标签:
@Table
@Data
public class awd {

	private Integer a;

	private Integer b;
}
CREATE TABLE awd(
a NUMERIC(8),
b NUMERIC(8))

为什么映射的是NUMERIC字段?
当我自定义CallBack时候,反射invoke执行报argument type mismatch异常

public class TransientCallBack extends EntityCallback {

    @Override
    protected Object process(ResultSet rs, Entity<?> entity, SqlContext context) throws SQLException {
        final Field[] fields = entity.getMirror().getFields(NutzTransient.class);
        ResultSetLooping ing = new ResultSetLooping() {
            protected boolean createObject(int index, ResultSet rs, SqlContext context, int rowCount) {
                Object obj = entity.getObject(rs, null);
                Method setMethod;
                for (Field field : fields) {
                    try {
                        NutzTransient nutzTransient = field.getAnnotation(NutzTransient.class);
                        String fieldDbName = Strings.isBlank(nutzTransient.value()) ? field.getName() : nutzTransient.value();
                        setMethod = entity.getMirror().getSetter(field);
                        if (null != setMethod) {
                            setMethod.invoke(obj, rs.getObject(fieldDbName));//我看numeric类型获取到对应的是BigDecimal,所以设置不进去,类型参数不匹配
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                list.add(obj);
                return true;
            }
        };
        ing.doLoop(rs, context);
        return ing.getList();
    }
}
4 回复

Castors转一下

已解决,但是具体不清楚为什么建表会自动映射NUMERIC类型而不是int4?

添加回复
请先登陆
回到顶部