NutzCN Logo
问答 使用UUID作为主键,并使用dao.insertOrUpdate(pojo)报错
发布于 165天前 作者 huc_y 173 次浏览 复制 上一个帖子 下一个帖子
标签:

实体类

@Table("pojo")
public class Pojo {

    @Name
    @Prev(els = @EL("uuid()"))
    @ColDefine(width = 32)
    private String uuid;

    @Column
    private int userid;

    @Column
    @ColDefine(width = 50)
    private String keySn;

    @Column
    @Comment("创建时间")
    private Timestamp ct;

//略 set get
}
 Pojo pojo= dao.fetch(Pojo.class, Cnd.where("userid", "=", userid));
        if (pojo== null) {
            pojo= new Pojo();
        }
        pojo.setCt(new Timestamp(System.currentTimeMillis()));
        pojo.setKeySn(SN);
        pojo.setUserid(userid);
      dao.insertOrUpdate(pojo);
org.nutz.dao.DaoException: java.lang.RuntimeException: r u kidding me?! It is impossible!
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	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.NutDao.fetch(NutDao.java:616)
	at org.nutz.dao.impl.NutDao.insertOrUpdate(NutDao.java:1069)
	at org.nutz.dao.impl.NutDao.insertOrUpdate(NutDao.java:1063)
7 回复

看上去是没判断@Name是否为null

  public <T> T fetch(T obj) {
        Entity<?> en = holder.getEntityBy(obj);
//错误源于下面这句
        Pojo pojo = pojoMaker.makeQuery(en)
                             .append(Pojos.Items.cndAuto(en, obj))
                             .setAfter(_pojo_fetchEntity)
                             .setPager(createPager(1, 1));
        _exec(pojo);
        return (T) pojo.getResult();
    }

看上去像bug,我看看怎么改

我发现你没把报错信息贴全:

org.nutz.dao.DaoException: java.lang.RuntimeException: r u kidding me?! It is impossible!
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	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.NutDao.fetch(NutDao.java:616)
	at org.nutz.dao.impl.NutDao.insertOrUpdate(NutDao.java:1068)
	at org.nutz.dao.impl.NutDao.insertOrUpdate(NutDao.java:1062)
	at org.nutz.dao.test.normal.SimpleDaoTest.test_issue_insert_or_update(SimpleDaoTest.java:1018)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.RuntimeException: r u kidding me?! It is impossible!
	at org.nutz.lang.Lang.impossible(Lang.java:119)
	at org.nutz.dao.impl.sql.pojo.SingleColumnCondtionPItem.joinParams(SingleColumnCondtionPItem.java:61)
	at org.nutz.dao.impl.jdbc.NutPojo.getParamMatrix(NutPojo.java:82)
	at org.nutz.dao.impl.sql.NutStatement.forPrint(NutStatement.java:197)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:20)
	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._runWithoutTransaction(NutDaoRunner.java:125)
	... 33 more

我提交了issue https://github.com/nutzam/nutz/issues/1297

已提交修正

哇,神速,赞一个

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