NutzCN Logo
问答 使用fieldfilter过滤字段后,fetch方法报过滤后的column不存在?
发布于 1280天前 作者 thineagle 1456 次浏览 复制 上一个帖子 下一个帖子
标签:

使用FieldFilter过滤查询结果时,被过滤的字段仍然包含在映射中,报了org.nutz.lang.born.BorningException异常,下面是日志其中id_type是表中的一个字段,调用fetch方法时使用FiledFilter过滤掉了这个字段。

Exception in thread "main" org.nutz.dao.DaoException: org.nutz.lang.born.BorningException: Fail to born or cast to 'mytools.test.dao.CustBasicInfo'
 by args: [@(com.alibaba.druid.pool.DruidPooledResultSet@4e70a728)]
 because:java.sql.SQLException: Column 'id_type' not found.
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:144)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:97)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:86)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:242)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:254)
	at org.nutz.dao.impl.NutDao.query(NutDao.java:490)
	at org.nutz.dao.impl.NutDao.fetch(NutDao.java:629)
	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:497)
	at org.nutz.dao.util.ExtDaoInvocationHandler$1.run(Daos.java:1182)
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:286)
	at org.nutz.dao.FieldFilter.run(FieldFilter.java:297)
	at org.nutz.dao.util.ExtDaoInvocationHandler.invoke(Daos.java:1199)
	at com.sun.proxy.$Proxy19.fetch(Unknown Source)
	at mytools.test.dao.TestDao.main(TestDao.java:47)
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'mytools.test.dao.CustBasicInfo'
 by args: [@(com.alibaba.druid.pool.DruidPooledResultSet@4e70a728)]
 because:java.sql.SQLException: Column 'id_type' not found.
	at org.nutz.lang.born.MethodBorning.born(MethodBorning.java:20)
	at org.nutz.dao.impl.entity.NutEntity.getObject(NutEntity.java:214)
	at org.nutz.dao.impl.sql.pojo.PojoQueryEntityCallback$1.createObject(PojoQueryEntityCallback.java:24)
	at org.nutz.dao.pager.ResultSetLooping.doLoop(ResultSetLooping.java:75)
	at org.nutz.dao.impl.sql.pojo.PojoQueryEntityCallback.invoke(PojoQueryEntityCallback.java:28)
	at org.nutz.dao.impl.jdbc.NutPojo.onAfter(NutPojo.java:114)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:280)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:59)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:65)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:63)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:138)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:163)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:130)
	... 16 more

程序片段类似下面的情况

  NutDao dao1 = new NutDao(datasource);
        CustBasicInfo info1 =    Daos.ext(dao1, FieldFilter.create( CustBasicInfo.class,"^(custNo|idNo|updTime|custName|)$")).fetch(CustBasicInfo.class);
1 回复

找到原因了, public static create(ResultSet rs){} // 工厂方法的名称可随意定 使用了快速构建, 默认get了所有字段。 这个快速构建的方法没有增加fieldmatcher, 导致不能判断是否使用字段过滤。 那么如果使用快速构建只能通过结果集是否包含字段来处理了吗?

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