NutzCN Logo
问答 queryByJoin regex是什么是 实体的关联字段的属性名称吗还是数据库表的字段的名字
发布于 2492天前 作者 qq_4945a577 1777 次浏览 复制 上一个帖子 下一个帖子
标签:
dao.queryByJoin(CheckDetail.class,"",cnd);
<T> List<T> queryByJoin(Class<T> classOfT, String regex, Condition cnd);

regex是什么是 实体的关联字段的属性名称吗还是数据库表的字段的名字,但是我都试过都不行,只有写null的时候才会执行关联查询

34 回复

关联字段属性名的正则表达式

为啥不设计成填属性名称???

Dao大部分都是正则表达式吧

你只需要查少数几个属性?

嗯,也就一或两个

哦,那还是用自定义sql吧

一开始不使用自定义sql是什么原因呢?回调不好选,还是条件不好拼呢?

sql语句和条件不好拼吧,(两张表关联),感觉写起来不想nutz简洁的那种风格了

Cndwhere(..).and(new Static("可以写任意合法的条件语句"))

new Static() 这是干什么用的?哪里有介绍??

试着写一下嘛,看看出来的语句,我相信你能明白的^_^

好啊,可是现在我用queryByJoin ( 我写了个正则表达式在网上验证过了是正确的)查出个异常,报“视图找不到”(我把sql拷贝到数据库执行正常)

贴一下报错信息和日志看看


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)

CHK_DATE 没表名称?? 话说, queryByJoin只处理@One关系哦...

一对多,当前类是一 , CHK_DATE 是当前类的属性

那也需要加上表名称...

这里有三个表 ABC ,A-B 是一对多 C-B是一对多 , 当前CHK是表B 但是我只想关联其中两张表查询(B到C)

不过, 除了数据库连错, 报" 表或视图不存在", 不晓得为啥

那是它自己生成出来的

哥你真是太厉害 你怎么想出来的

我用的单元测试,它去找testResources了

麻烦把帖子删了吧

queryByJoin要进行分页查询的时候dao.count没有关联查询的方法啊

哦, 报个issue吧

还有个问题:

List<Pet> list = dao.query(Pet.class, null, pager);
    //pager.setRecordCount(dao.count(Pet.class));
pager.setRecordCount(list.size());//这样可不可以

issue地址是多少

数据量少还好, 多了就作死了...

而且还有去重的情况没有,当我拼sql查询的时候要对一个字段进行去重(distinct :select distinct t.a ,t2.aa from ....join ....on ...where t.a='a' and t2.aa='aa')

而且queryByJoin 还有去重的情况没有,当我拼sql查询的时候要对一个字段进行去重(distinct :select distinct t.a ,t2.aa from ....join ....on ...where t.a='a' and t2.aa='aa')

我关联表分页查询只能拼SQL了吗

嗯,先用自定义sql解决吧

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