大家有没有遇到 postgresql 数据库 ORM查询报异常,但是用sqlcallback 却成功的问题?
List infos = dao.query(Comminfo.class, Cnd.where("bcdtype", "=", 0), dao.createPager(1, 50));
该查询会报异常
Exception in thread "main" org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT * FROM COMMINFO WHERE BCDTYPE=? LIMIT 50 OFFSET 0
| 1 |
|---|
| 0 |
For example:> "SELECT * FROM COMMINFO WHERE BCDTYPE=0 LIMIT 50 OFFSET 0 "'
PreparedStatement:
'SELECT * FROM COMMINFO WHERE BCDTYPE=? LIMIT 50 OFFSET 0 '
CaseMessage=错误: 操作符不存在: integer = character varying
建议:没有匹配指定名称和参数类型的操作符. 您也许需要增加明确的类型转换.
位置:38
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:96)
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:316)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:38)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
at org.nutz.dao.impl.DaoSupport$DaoExec.run(DaoSupport.java:306)
at org.nutz.trans.Trans.exec(Trans.java:174)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:276)
at org.nutz.dao.impl.NutDao.query(NutDao.java:465)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)
at com.beyondb.beidou.test.PGQueryTest.main(PGQueryTest.java:51)
Caused by: org.postgresql.util.PSQLException: 错误: 操作符不存在: integer = character varying
建议:没有匹配指定名称和参数类型的操作符. 您也许需要增加明确的类型转换.
位置:38
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:228)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:45)
... 8 more
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:228)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:45)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:316)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:38)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
at org.nutz.dao.impl.DaoSupport$DaoExec.run(DaoSupport.java:306)
at org.nutz.trans.Trans.exec(Trans.java:174)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:276)
at org.nutz.dao.impl.NutDao.query(NutDao.java:465)
at com.beyondb.beidou.test.PGQueryTest.main(PGQueryTest.java:51)
但是SqlCallback 模式却不会,两者生成的sql应该都是一样的
String sql = "SELECT * FROM COMMINFO WHERE bcdtype=@bcd LIMIT 50 OFFSET 1";
Sql sqls = Sqls.create(sql);
sqls.params().set("bcd", 0);
sqls.setCallback(new SqlCallback() {
@Override
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
int cmmid = 0;
while (rs.next()) {
cmmid = rs.getInt("commid");
System.out.println(cmmid);
}
return cmmid;
}
});
dao.execute(sqls);
这个是数据库的问题,还是 Nutz 的ORM问题?