NutzCN Logo
问答 dao.insert(entity,filter) 忽略null值无效
发布于 3252天前 作者 keniushadu 3323 次浏览 复制 上一个帖子 下一个帖子
标签:
    代码: 
    	Bean entity = new Bean();
        FieldFilter filter = FieldFilter.create(clazz, true);
        entity = dao.insert(entity,filter);

异常信息
org.nutz.dao.DaoException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'type' cannot be null
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:54) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:202) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.impl.DaoSupport$DaoExec.run(DaoSupport.java:269) ~[nutz-1.r.54.jar:na]
	at org.nutz.trans.Trans.exec(Trans.java:174) ~[nutz-1.r.54.jar:na]
	at org.nutz.trans.Trans.exec(Trans.java:132) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:239) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:144) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.impl.NutDao$2.run(NutDao.java:153) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:285) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:151) ~[nutz-1.r.54.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_80]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_80]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_80]
	at org.nutz.dao.util.ExtDaoInvocationHandler$1.run(Daos.java:929) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:285) ~[nutz-1.r.54.jar:na]
	at org.nutz.dao.util.ExtDaoInvocationHandler.invoke(Daos.java:951) ~[nutz-1.r.54.jar:na]
	at com.sun.proxy.$Proxy27.insert(Unknown Source) ~[na:na]
	
CREATE TABLE `bean` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` bigint(20) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10000005 DEFAULT CHARSET=utf8;

6 回复

问题是, nutz输出的sql呢?

@wendal INSERT INTO mx_quanid_gen(type) VALUES(NULL)

@wendal Daos.ext(dao, filter).insert(bean); 用这个写法一样. 执行Sql也一样

"INSERT INTO bean(type) VALUES(NULL)"

哦, dao.insert不直接支持过滤空值...

@wendal 兽总给个解决办法?

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