NutzCN Logo
问答 奇怪的问题,dao报空指针
发布于 2520天前 作者 wx_042ohr4pop5lq7kbg8l6 2074 次浏览 复制 上一个帖子 下一个帖子
标签:
@IocBean(args = {"refer:dao2"})
public class UserDB2AccountServiceImpl extends BaseServiceImpl<User> implements UserDB2AccountService
Sql sql = XXXXXXX;
log.info(this.dao()); //通过
log.info(this.dao().count("abc")); //通过,并且结果正确
this.dao().execute(sql); //java.lang.NullPointerException

从计划任务进
sql字符串能正确拼接,
直接在sql里也能查出结果
最诡异的是,从controller进来这个方法就没问题
如何定位这个空指针?

20 回复

报错信息贴来看看

e = org.nutz.dao.DaoException: java.lang.NullPointerException
detailMessage = java.lang.NullPointerException
stackTrace = StackTraceElement[0]@10570
suppressedExceptions =  size = 0

??? 你这是怎么打印日志的?

try {
 ..........
}
catch (Throwable e) {
        log.info(e.getMessage(), e);
}

我e.printStackTrace()看看..才发现写的是toString,没打出堆栈

org.nutz.dao.DaoException: java.lang.NullPointerException
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:115)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:88)
	at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:74)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:72)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:236)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:1008)
	at cn.wizzer.app.user.modules.services.impl.UserDB2AccountServiceImpl.getEndProjectListByFinishTime(UserDB2AccountServiceImpl.java:113)
	at cn.wizzer.app.web.commons.quartz.job.UpdateProjectJob.execute(UpdateProjectJob.java:80)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException
	at org.nutz.dao.jdbc.Jdbcs.guessEntityFieldColumnType(Jdbcs.java:866)
	at org.nutz.dao.impl.sql.NutStatement.getAdapterBy(NutStatement.java:337)
	at org.nutz.dao.impl.sql.NutSql$SqlParamPItem.joinAdaptor(NutSql.java:315)
	at org.nutz.dao.impl.sql.NutSql.getAdaptors(NutSql.java:105)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:259)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104)
	... 12 more

代码贴一下看看

另外,nutz版本多少

外面包了事物

 try {
                Trans.begin();
                try {
                    userDB2AccountService.getProjectListByCreateTime(user, startDate, endDate);
                    userDB2AccountService.getEndProjectListByFinishTime(user, startDate, endDate);
                    Trans.commit();
                } catch (Exception e) {
                    Trans.rollback();
                } finally {
                    Trans.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

wk-framework
4.0.1-SNAPSHOT
没升级过

里面

       Sql sql = Sqls.queryRecord("SELECT a.b_aid,a.b_update,product.a_name,a.b_a_num,a.b_subnum,a.b_account " +
                "FROM z_da a LEFT JOIN z_customer customer ON a.b_dcode=customer.d_code " +
                "LEFT JOIN z_product product ON a.b_acode=product.a_code WHERE (customer.d_mobile=@mobile OR customer.d_tel=@mobile)");
        sql.params().set("mobile", user.getMobile());
        this.dao().execute(sql);

能找到Jdbcs.java:866的代码不? 因为最新的nutz代码里面, 866是空行

        }
        /*
         * 上面的都不是? 那就当作字符串好了,反正可以 toString
         */
        else {
            if (log.isDebugEnabled())
                log.debugf("take field '%s(%s)'(%s) as VARCHAR(%d)",
                           ef.getName(),
                           Lang.getTypeClass(ef.getType()).getName(),
                           ef.getEntity().getType().getName(),   //866
                           Daos.DEFAULT_VARCHAR_WIDTH);
            ef.setColumnType(ColType.VARCHAR);
            ef.setWidth(Daos.DEFAULT_VARCHAR_WIDTH);
        }
    }

看看pom.xml里面nutz版本是多少

哦, 有点老, 改成 1.r.63-SNAPSHOT 试试

找到问题了. 日期不小心用了DateTime,导致ef找不到类型,全都toSqlDate就好了..

DateTime ?? 具体是什么类?

joda的DateTime吗?

-_-# 是我的错.
hutool 这个库的类,太不小心了...,需要toXX才能使用

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