NutzCN Logo
问答 插入主键遇到个问题,主键没设置自增
发布于 2769天前 作者 SayingCode 2181 次浏览 复制 上一个帖子 下一个帖子
标签:

我的数据库建表语句是
create table tab_userinfo
(
id int not null comment '主键',
aid int not null comment '关联账户id'
primary key (id)
}

dao结构
class Tab_userinfo{
@Column
@Id
@Prev({
@SQL(db = DB.ORACLE, value="SELECT TAB_USERINFO_S.nextval FROM dual")
})
private Integer id;
...
get() set()
...
}

插入方式
Tab_userinfo _item = new Tab_userinfo();
_item.setid(xxxx);
dao().insert(_item)
执行插入的时候提示主键id不能为空

2 回复

错误日志
For example:> "INSERT INTO tab_userinfo(email,invitation_code) VALUES(NULL,'7a45e022349748c79942f6af4581e18f') "
。。。
2016-08-29 18:22:47,663 org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:89) DEBUG - SQLException
java.sql.SQLException: Field 'id' doesn't have a default value

。。。

很奇怪,打印的日志中看出insert语句根本就不包含我的setid的主键id值

改成非自动.

@Id(auto=false)

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