dao.queryByJoin(CheckDetail.class,"",cnd);
<T> List<T> queryByJoin(Class<T> classOfT, String regex, Condition cnd);
regex是什么是 实体的关联字段的属性名称吗还是数据库表的字段的名字,但是我都试过都不行,只有写null的时候才会执行关联查询
dao.queryByJoin(CheckDetail.class,"",cnd);
<T> List<T> queryByJoin(Class<T> classOfT, String regex, Condition cnd);
regex是什么是 实体的关联字段的属性名称吗还是数据库表的字段的名字,但是我都试过都不行,只有写null的时候才会执行关联查询
cnd.where().and("SPEC(数据库表名).operate","like",name+"%").and("SPEC.dep","=",dep).and("chkdate","<",date);
list = dao.queryByJoin(Chk(实体名与SPEC是一对多).class,"^[A-Za-z]+$",cnd);
Get 'dao'<interface org.nutz.dao.Dao>
2018-01-19 15:05:20,393 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT Chk.id as id,Chk.CHECK_DATE as CHECK_DATE,Chk.other as other,Chk.CHECK_STATUS as CHECK_STATUS,Chk.information as information,Chk.RES_TIME as RES_TIME,Chk.SOL_TIME as SOL_TIME,Chk.solution as solution,Chk.DICTIONARY_ID as DICTIONARY_ID,Chk.OPERATE_ID as OPERATE_ID , DICTIONARYS.id as DICTIONARYS_z_id,DICTIONARYS.PARENT_ID as DICTIONARYS_z_PARENT_ID,DICTIONARYS.NAME as DICTIONARYS_z_NAME,DICTIONARYS.PATH as DICTIONARYS_z_PATH , SPEC.id as SPEC_z_id,SPEC.dep_ID as SPEC_z_dep_ID,SPEC.dep as SPEC_z_dep,SPEC.operate as SPEC_z_operate FROM Chk LEFT JOIN DICTIONARYS ON Chk.DICTIONARY_ID = DICTIONARYS.id LEFT JOIN SPEC ON Chk.OPERATE_ID = SPEC.id WHERE SPEC.operate LIKE ? AND SPEC.dep=?
| 1 | 2 |
|------|------|
| 小明% | 中心 |
For example:> "SELECT Chk.id as id,Chk.CHECK_DATE as CHECK_DATE,Chk.other as other,Chk.CHECK_STATUS as CHECK_STATUS,Chk.information as information,Chk.RES_TIME as RES_TIME,Chk.SOL_TIME as SOL_TIME,Chk.solution as solution,Chk.DICTIONARY_ID as DICTIONARY_ID,Chk.OPERATE_ID as OPERATE_ID , DICTIONARYS.id as DICTIONARYS_z_id,DICTIONARYS.PARENT_ID as DICTIONARYS_z_PARENT_ID,DICTIONARYS.NAME as DICTIONARYS_z_NAME,DICTIONARYS.PATH as DICTIONARYS_z_PATH , SPEC.id as SPEC_z_id,SPEC.dep_ID as SPEC_z_dep_ID,SPEC.dep as SPEC_z_dep,SPEC.operate as SPEC_z_operate FROM Chk LEFT JOIN DICTIONARYS ON Chk.DICTIONARY_ID = DICTIONARYS.id LEFT JOIN SPEC ON Chk.OPERATE_ID = SPEC.id WHERE SPEC.operate LIKE '管理员%' AND SPEC.dep='信息中心'AND CHK_DATE<'2018-01-19 15:12:21'"
2018-01-19 15:05:20,447 org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:97) DEBUG - SQLException
java.sql.SQLSyntaxErrorException: ORA-00942: 表或视图不存在
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:886)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1175)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1296)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1495)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:227)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:272)
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.plugins.cache.dao.DaoCacheInterceptor._exec(DaoCacheInterceptor.java:28)
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:187)
at org.nutz.plugins.cache.dao.DaoCacheInterceptor.filter(DaoCacheInterceptor.java:18)
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)
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.queryByJoin(NutDao.java:1173)
at org.nutz.dao.impl.NutDao.queryByJoin(NutDao.java:1163)
at org.sys.ins.service.InsServiceImpl.querySPEC2(InsServiceImpl.java:108)
at org.mytest.ty.test.NutzJunitTest.test8(NutzJunitTest.java:95)
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:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:33)
at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:14)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT Chk.id as id,Chk.CHECK_DATE as CHECK_DATE,Chk.other as other,Chk.CHECK_STATUS as CHECK_STATUS,Chk.information as information,Chk.RES_TIME as RES_TIME,Chk.SOL_TIME as SOL_TIME,Chk.solution as solution,Chk.DICTIONARY_ID as DICTIONARY_ID,Chk.OPERATE_ID as OPERATE_ID , DICTIONARYS.id as DICTIONARYS_z_id,DICTIONARYS.PARENT_ID as DICTIONARYS_z_PARENT_ID,DICTIONARYS.NAME as DICTIONARYS_z_NAME,DICTIONARYS.PATH as DICTIONARYS_z_PATH , SPEC.id as SPEC_z_id,SPEC.dep_ID as SPEC_z_dep_ID,SPEC.dep as SPEC_z_dep,SPEC.operate as SPEC_z_operate FROM Chk LEFT JOIN DICTIONARYS ON Chk.DICTIONARY_ID = DICTIONARYS.id LEFT JOIN SPEC ON Chk.OPERATE_ID = SPEC.id WHERE SPEC.operate LIKE '管理员%' AND SPEC.dep='信息中心'AND CHK_DATE<'2018-01-19 15:12:21'"'
PreparedStatement:
'SELECT Chk.id as id,Chk.CHECK_DATE as CHECK_DATE,Chk.other as other,Chk.CHECK_STATUS as CHECK_STATUS,Chk.information as information,Chk.RES_TIME as RES_TIME,Chk.SOL_TIME as SOL_TIME,Chk.solution as solution,Chk.DICTIONARY_ID as DICTIONARY_ID,Chk.OPERATE_ID as OPERATE_ID , DICTIONARYS.id as DICTIONARYS_z_id,DICTIONARYS.PARENT_ID as DICTIONARYS_z_PARENT_ID,DICTIONARYS.NAME as DICTIONARYS_z_NAME,DICTIONARYS.PATH as DICTIONARYS_z_PATH , SPEC.id as SPEC_z_id,SPEC.dep_ID as SPEC_z_dep_ID,SPEC.dep as SPEC_z_dep,SPEC.operate as SPEC_z_operate FROM Chk LEFT JOIN DICTIONARYS ON Chk.DICTIONARY_ID = DICTIONARYS.id LEFT JOIN SPEC ON Chk.OPERATE_ID = SPEC.id WHERE SPEC.operate LIKE ? AND SPEC.dep=? AND CHK_DATE<?'
CaseMessage=ORA-00942: 表或视图不存在
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
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.plugins.cache.dao.DaoCacheInterceptor._exec(DaoCacheInterceptor.java:28)
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:187)
at org.nutz.plugins.cache.dao.DaoCacheInterceptor.filter(DaoCacheInterceptor.java:18)
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)
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.queryByJoin(NutDao.java:1173)
at org.nutz.dao.impl.NutDao.queryByJoin(NutDao.java:1163)
还有个问题:
List<Pet> list = dao.query(Pet.class, null, pager);
//pager.setRecordCount(dao.count(Pet.class));
pager.setRecordCount(list.size());//这样可不可以
而且还有去重的情况没有,当我拼sql查询的时候要对一个字段进行去重(distinct :select distinct t.a ,t2.aa from ....join ....on ...where t.a='a' and t2.aa='aa')