NutzCN Logo
问答 使用FieldFilter查询list 报错了
发布于 2402天前 作者 Leewell1989 1857 次浏览 复制 上一个帖子 下一个帖子
标签:

代码:

FieldFilter ff = FieldFilter.locked(BaseInfoEntity.class, "^data$");
        Criteria cri = services.createCriteria(b);
        Pager pager = super.dao().createPager(pageNum, pageSize);
        // 或者用Daos.ext
        return Daos.ext(super.dao(), ff).query(BaseInfoEntity.class, cri, pager);

日志

23:31:10.425 [main] DEBUG o.n.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT CRDT_CODE,COMP_NAME,COMP_TYPE,LGL_PRSN,RGST_CAPI,ESTB_DATE,ADDR,FARE_PLC,OPER_TERM_STRT,OPER_TERM_END,OPER_RNG,SIGN_ORGN,APPR_DATE,SIGN_STTS,OV_TYPE,ip_addr,ov_date,ov_rslt FROM AMS_ENT_BASE_INFO  WHERE LOWER(COMP_NAME) LIKE LOWER(?)) T WHERE ROWNUM <= 10) WHERE RN > 0 
    |                1 |
    |------------------|
    | %海门市海门镇华丰热水器经营部% |
  For example:> "SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT CRDT_CODE,COMP_NAME,COMP_TYPE,LGL_PRSN,RGST_CAPI,ESTB_DATE,ADDR,FARE_PLC,OPER_TERM_STRT,OPER_TERM_END,OPER_RNG,SIGN_ORGN,APPR_DATE,SIGN_STTS,OV_TYPE,ip_addr,ov_date,ov_rslt FROM AMS_ENT_BASE_INFO  WHERE LOWER(COMP_NAME) LIKE LOWER('%海门市海门镇华丰热水器经营部%')) T WHERE ROWNUM <= 10) WHERE RN > 0 "
23:31:10.572 [main] DEBUG c.a.druid.pool.PreparedStatementPool - stmt enter cache
23:31:10.576 [main] ERROR com.yuro.web.BaseHandler - 
org.nutz.dao.DaoException: org.nutz.lang.born.BorningException: Fail to born or cast to 'com.yuro.ams.bean.ent.BaseInfoEntity'
 by args: [@(com.alibaba.druid.pool.DruidPooledResultSet@1ef4b2b)]
 because:java.lang.ClassCastException: com.alibaba.druid.pool.DruidPooledResultSet cannot be cast to java.util.Map
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:140) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:93) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:82) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.NutDao.query(NutDao.java:483) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_26]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_26]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_26]
	at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_26]
	at org.nutz.dao.util.ExtDaoInvocationHandler$1.run(Daos.java:1093) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:286) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:297) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.util.ExtDaoInvocationHandler.invoke(Daos.java:1109) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at $Proxy21.query(Unknown Source) ~[na:na]
	at com.yuro.ams.service.ent.BaseInfoService.query(BaseInfoService.java:60) ~[classes/:na]
	at com.yuro.ams.handler.AccountInfoHandler.queryOvRecord(AccountInfoHandler.java:161) ~[classes/:na]
	at com.yuro.ams.handler.AccountInfoHandler$$NUTZAOP._aop_invoke(AccountInfoHandler.java:3) [nutz-1.r.63.r4.jar:na]
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77) [nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57) [nutz-1.r.63.r4.jar:1.r.63.r4]
	at com.yuro.log.LogInterceptor.filter(LogInterceptor.java:16) [log-saber-1.0.10.jar:na]
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60) [nutz-1.r.63.r4.jar:1.r.63.r4]
	at com.yuro.ams.handler.AccountInfoHandler$$NUTZAOP.queryOvRecord(AccountInfoHandler.java:1) [nutz-1.r.63.r4.jar:na]
	at com.yuro.ams.handler.AccountInfoHandlerTest.testQuery(AccountInfoHandlerTest.java:47) [test-classes/:na]
	at com.yuro.ams.handler.AccountInfoHandlerTest$$NUTZAOP._aop_invoke(AccountInfoHandlerTest.java:3) [nutz-1.r.63.r4.jar:na]
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77) [nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57) [nutz-1.r.63.r4.jar:1.r.63.r4]
	at com.yuro.log.LogInterceptor.filter(LogInterceptor.java:16) [log-saber-1.0.10.jar:na]
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60) [nutz-1.r.63.r4.jar:1.r.63.r4]
	at com.yuro.ams.handler.AccountInfoHandlerTest$$NUTZAOP.testQuery(AccountInfoHandlerTest.java:1) [nutz-1.r.63.r4.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_26]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_26]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_26]
	at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_26]
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) [junit-4.12.jar:4.12]
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:33) [nutz-plugins-mock-1.r.63.r4.jar:na]
	at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:14) [nutz-plugins-mock-1.r.63.r4.jar:na]
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137) [junit-4.12.jar:4.12]
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) [junit-rt.jar:na]
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) [junit-rt.jar:na]
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) [junit-rt.jar:na]
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) [junit-rt.jar:na]
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'com.yuro.ams.bean.ent.BaseInfoEntity'
 by args: [@(com.alibaba.druid.pool.DruidPooledResultSet@1ef4b2b)]
 because:java.lang.ClassCastException: com.alibaba.druid.pool.DruidPooledResultSet cannot be cast to java.util.Map
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:25) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.entity.NutEntity.getObject(NutEntity.java:205) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.pojo.PojoQueryEntityCallback$1.createObject(PojoQueryEntityCallback.java:24) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.pager.ResultSetLooping.doLoop(ResultSetLooping.java:75) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.pojo.PojoQueryEntityCallback.invoke(PojoQueryEntityCallback.java:28) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:114) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:277) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:159) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:126) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	... 52 common frames omitted
Caused by: java.lang.ClassCastException: com.alibaba.druid.pool.DruidPooledResultSet cannot be cast to java.util.Map
	at org.nutz.mapl.impl.MaplRebuild.injectMap(MaplRebuild.java:189) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.mapl.impl.MaplRebuild.inject(MaplRebuild.java:156) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.mapl.impl.MaplRebuild.injectMap(MaplRebuild.java:220) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.mapl.impl.MaplRebuild.inject(MaplRebuild.java:156) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.mapl.impl.MaplRebuild.cell(MaplRebuild.java:92) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.mapl.Mapl.cell(Mapl.java:56) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at com.yuro.ams.bean.ent.BaseInfoEntity.<init>(BaseInfoEntity.java:122) ~[classes/:na]
	at com.yuro.ams.bean.ent.BaseInfoEntity$FC$c90bfb1bcd4882a6037d8f4c91dd4a90.invoke(BaseInfoEntity.java) ~[nutz-1.r.63.r4.jar:na]
	at org.nutz.lang.born.AbstractConstructorBorning.call(AbstractConstructorBorning.java:25) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19) ~[nutz-1.r.63.r4.jar:1.r.63.r4]
	... 65 common frames omitted

是用法有问题吗?

12 回复

BaseInfoEntity是怎样的?

所有属性public,没写getter/setter

贴出来看看

package com.yuro.ams.bean.ent;

import org.nutz.dao.entity.annotation.*;
import org.nutz.lang.Strings;
import org.nutz.mapl.Mapl;

import java.util.Date;

/**
 * Desc: 企业基本信息
 * Created by leewell on 2016/11/17.
 */
@Table("AMS_ENT_BASE_INFO")
    public class BaseInfoEntity {

    @Column("CRDT_CODE")
    @Comment("统一社会信用代码")
    public String creditCode;

    @Column("COMP_NAME")
    @Comment("名称")
    public String name;

    @Column("COMP_TYPE")
    @Comment("类型")
    public String type;

    @Column("LGL_PRSN")
    @Comment("法定代表人")
    public String lglPerson;

    @Column("RGST_CAPI")
    @Comment("注册资本")
    public String rgstCapital;

    @Column("ESTB_DATE")
    @Comment("成立日期")
    public String estbDate;

    @Column("ADDR")
    @Comment("经营地址")
    @ColDefine(type = ColType.VARCHAR, width = 1000)
    public String address;

    @Column("FARE_PLC")
    @Comment("住所")
    @ColDefine(type = ColType.VARCHAR, width = 1000)
    public String farePlace;

    @Column("OPER_TERM_STRT")
    @Comment("经营期限自")
    public String operTermStart;

    @Column("OPER_TERM_END")
    @Comment("经营期限至")
    public String operTermEnd;

    @Column("OPER_RNG")
    @Comment("经营范围")
    @ColDefine(type = ColType.VARCHAR, width = 1000)
    public String operRange;

    @Column("SIGN_ORGN")
    @Comment("登记机关")
    public String signOrgan;

    @Column("APPR_DATE")
    @Comment("核准日期")
    public String apprDate;

    @Column("SIGN_STTS")
    @Comment("登记状态")
    public String signStatus;

    @Column("OV_TYPE")
    @Comment("核查方式")
    public String ovType;

    @Column("ip_addr")
    @Comment("客户端IP")
    public String ip;

    @Column
    @Comment("接口数据")
    @ColDefine(type = ColType.TEXT)
    public String data;

    @Column("ov_date")
    @Comment("核查日期")
    @ColDefine(type = ColType.VARCHAR, width = 20)
    public Date ovDate;

    @Column("ov_rslt")
    @Comment("核查结果")
    @ColDefine(type = ColType.VARCHAR, width = 20)
    public String ovResult;


    public BaseInfoEntity(BaseInfoModel baseInfoModel) {
        this.creditCode = baseInfoModel.REG_NO;
        this.name = baseInfoModel.CORP_NAME;
        this.type = baseInfoModel.ZJ_ECON_KIND;
        this.lglPerson = baseInfoModel.OPER_MAN_NAME;
        this.rgstCapital = "个体工商户".equals(baseInfoModel.ZJ_ECON_KIND) ? " " : baseInfoModel.REG_CAPI;
        this.estbDate = baseInfoModel.START_DATE;
        this.farePlace = baseInfoModel.ADDR;
        //this.address = Strings.isNotBlank(baseInfoModel.FARE_PLACE) ? baseInfoModel.FARE_PLACE : baseInfoModel.ADDR;
        this.address = "个体工商户".equals(baseInfoModel.ZJ_ECON_KIND) ?  baseInfoModel.FARE_PLACE : baseInfoModel.ADDR;
        this.operTermStart = baseInfoModel.FARE_TERM_START;
        this.operTermEnd = Strings.isEmpty(baseInfoModel.FARE_TERM_END) ? "99991231" : baseInfoModel.FARE_TERM_END;
        this.operRange = baseInfoModel.FARE_SCOPE;
        this.signOrgan = baseInfoModel.BELONG_ORG;
        this.apprDate = baseInfoModel.CHECK_DATE;
        this.signStatus = baseInfoModel.CORP_STATUS;

    }

    public BaseInfoEntity() {
    }

    public BaseInfoEntity(Object obj) {
        this.creditCode = (String) Mapl.cell(obj, "Result.CreditCode");
        this.name = (String) Mapl.cell(obj, "Result.Name");
        this.type = (String) Mapl.cell(obj, "Result.EconKind");
        this.lglPerson = (String) Mapl.cell(obj, "Result.OperName");
        this.rgstCapital = (String) Mapl.cell(obj, "Result.RegistCapi");
        this.estbDate = (String) Mapl.cell(obj, "Result.StartDate");
//        this.farePlace = (String) Mapl.cell(obj, "Address");
        this.address = (String) Mapl.cell(obj, "Result.Address");;
        this.operTermStart = (String) Mapl.cell(obj, "Result.TermStart");
        this.operTermEnd = (String) Mapl.cell(obj, "Result.TeamEnd");
        this.operRange = (String) Mapl.cell(obj, "Result.Scope");
        this.signOrgan = (String) Mapl.cell(obj, "Result.BelongOrg");
        this.apprDate = (String) Mapl.cell(obj, "Result.CheckDate");
        this.signStatus = (String) Mapl.cell(obj, "Result.Status");
    }


}

public BaseInfoEntity(Object obj)

这个构造方法去掉试试

我先传String进来在转换成json对象吧。之前是转好了传进来的

改成

public BaseInfoEntity(Map obj) {

public BaseInfoEntity(ResultSet obj) { // 被当成来匹配了
添加回复
请先登陆
回到顶部