测试代码:
Record row = new Record();
row.set(".table","test");
row.set("createTime",new Timestamp(System.currentTimeMillis()));
row.set("updateTime",null);
dao.fastInsert(row);
log4j: 2017-07-14 10:02:18,162 [main] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SQLException
org.postgresql.util.PSQLException: ERROR: column "updatetime" is of type timestamp without time zone but expression is of type character varying
建议:You will need to rewrite or cast the expression.
位置:450
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:410)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:448)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:261)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:76)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:249)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:64)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:204)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.fastInsert(NutDao.java:171)
at com.gzx.hr.test.GzxHrTestMain$4.invoke(GzxHrTestMain.java:170)
at com.gzx.hr.test.GzxHrTestMain$4.invoke(GzxHrTestMain.java:1)
跟踪问题,猜测原因是
EntityHolder中,猜测数据库类型null的情况直接当做varchar处理,导致实际插入执行的是
stat.setNull(i, Types.NULL);
非 stat.setNull(i, Types.TIMESTAMP);
// 猜测一下数据库类型
Jdbcs.guessEntityFieldColumnType(ef); // 做ColType.VARCHAT处理
ef.setAdaptor(support.expert.getAdaptor(ef));