我本地测试, 重复的name是会抛出Duplicate entry的:
dao.create(User.class, false);
dao.insert(new User("wendal", ....));
dao.insert(new User("wendal", ....));
11:05:52.739 DEBUG (NutDaoExecutor.java:388) printSQL - CREATE TABLE t_user(
id INT(32),
name VARCHAR(50) UNIQUE NOT NULL,
passwd VARCHAR(128),
salt VARCHAR(50),
locked BOOLEAN,
ct DATETIME,
ut DATETIME,
PRIMARY KEY (id)
) ENGINE=InnoDB CHARSET=utf8
org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO t_user(name,passwd,salt,locked,ct,ut) VALUES('wendal','f332a8fd2315a0fa21adbc25fc9fc6c239fc97b16d33fa74ff898f92a6bef51a','dc39d4c131b941db943fed3f1968f475',false,'2016-11-09 11:05:54','2016-11-09 11:05:54') '
PreparedStatement:
'INSERT INTO t_user(name,passwd,salt,locked,ct,ut) VALUES(?,?,?,?,?,?) '
CaseMessage=Duplicate entry 'wendal' for key 'name'
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:102) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.interceptor.DaoTimeInterceptor.filter(DaoTimeInterceptor.java:23) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.plugins.cache.dao.DaoCacheInterceptor._exec(DaoCacheInterceptor.java:28) ~[nutz-plugins-daocache-1.r.58.jar:?]
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:96) ~[nutz-plugins-daocache-1.r.58.jar:?]
at org.nutz.plugins.cache.dao.DaoCacheInterceptor.filter(DaoCacheInterceptor.java:18) ~[nutz-plugins-daocache-1.r.58.jar:?]
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:93) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:77) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:63) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.trans.Trans.exec(Trans.java:174) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:61) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:234) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:242) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.NutDao.insert(NutDao.java:157) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at net.wendal.nutzbook.service.UserService.add(UserService.java:35) ~[classes/:?]
at net.wendal.nutzbook.service.UserService$$NUTZAOP._aop_invoke(UserService.java:1) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at net.wendal.nutzbook.service.syslog.SysLogAopInterceptor.filter(SysLogAopInterceptor.java:59) ~[classes/:?]
at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at net.wendal.nutzbook.service.UserService$$NUTZAOP.add(UserService.java:1) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at net.wendal.nutzbook.MainSetup.init(MainSetup.java:209) ~[classes/:?]
at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:277) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121) [nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19) [nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.mvc.NutFilter._init(NutFilter.java:87) [nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.mvc.NutFilter.init(NutFilter.java:65) [nutz-1.r.59-SNAPSHOT.jar:?]
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) [catalina.jar:9.0.0.M9]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) [catalina.jar:9.0.0.M9]
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) [catalina.jar:9.0.0.M9]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4561) [catalina.jar:9.0.0.M9]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5203) [catalina.jar:9.0.0.M9]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) [catalina.jar:9.0.0.M9]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) [catalina.jar:9.0.0.M9]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) [catalina.jar:9.0.0.M9]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) [catalina.jar:9.0.0.M9]
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596) [catalina.jar:9.0.0.M9]
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805) [catalina.jar:9.0.0.M9]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_112]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_112]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_112]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_112]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_112]
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'wendal' for key 'name'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_112]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_112]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_112]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_112]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:934) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192) ~[mysql-connector-java-5.1.39.jar:5.1.39]
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2931) ~[druid-1.0.25.jar:1.0.25]
at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440) ~[druid-1.0.25.jar:1.0.25]
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2929) ~[druid-1.0.25.jar:1.0.25]
at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:131) ~[druid-1.0.25.jar:1.0.25]
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493) ~[druid-1.0.25.jar:1.0.25]
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308) ~[nutz-1.r.59-SNAPSHOT.jar:?]
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90) ~[nutz-1.r.59-SNAPSHOT.jar:?]
... 49 more