NutzCN Logo
问答 uuid主键没有生成?
发布于 14天前 作者 qq_a930202f 49 次浏览 复制 上一个帖子 下一个帖子
标签:
java.sql.SQLException: Field 'id' doesn't have a default value

实体

	@Name
	@Prev(els = { @EL("uuid(32)") })
	protected String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

页面提交

@Param("..")Comment comment

debug 提交过来的comment的id是null
然后

_insert(obj, true,false, false);

就报错了,哪里用法不对吗?

6 回复

实体和日志贴全一点

来自美丽的 NutzCN

@zozoh

org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:97) - SQLException
java.sql.SQLException: Field 'id' doesn't have a default value
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1203) ~[mysql-connector-java-5.1.35.jar:5.1.35]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2931) ~[druid-1.0.23.jar:1.0.23]
	at com.alibaba.druid.wall.WallFilter.preparedStatement_execute(WallFilter.java:600) ~[druid-1.0.23.jar:1.0.23]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2929) ~[druid-1.0.23.jar:1.0.23]
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440) ~[druid-1.0.23.jar:1.0.23]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2929) ~[druid-1.0.23.jar:1.0.23]
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:131) ~[druid-1.0.23.jar:1.0.23]
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493) ~[druid-1.0.23.jar:1.0.23]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308) ~[nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:88) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:74) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.trans.Trans.exec(Trans.java:174) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:72) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:148) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.NutDao$17.run(NutDao.java:1031) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:286) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:297) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:1035) [nutz-1.r.62.jar:1.r.62]
	at org.nutz.service.EntityService._insert(EntityService.java:363) [nutz-1.r.62.jar:1.r.62]
	at net.gg.service.BaseService.insert_(BaseService.java:168) [classes/:?]

实体是继承抽象类。

public abstract class UuidEntity <T> extends DataEntity<T>{
	private static final long serialVersionUID = 1L;
	
	public UuidEntity() {
		super();
	}

	
	public UuidEntity(String id){
		this();
		this.id = id;
	}
	
	@Name
	@Prev(els = { @EL("uuid(32)") })
	protected String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
 
}

ignoreNull的时候把name忽略了吧,直接dao.insert(obj) 啦

@wendal 哦哦,我试试,那在插入的时候有需要ignoreNull的场景吗?

看上去像bug,报个issue吧

非主键字段

来自美丽的 NutzCN

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