detachedcriteria-Hiberate 用detached作子查询 报空指针异常

问题描述

Hiberate 用detached作子查询 报空指针异常
 DetachedCriteria dc = DetachedCriteria.forClass(Course.class);DetachedCriteria subselect = DetachedCriteria.forClass(CoursePlan.class)                .add(Restrictions.eq(""schoolYear"" schoolYear));dc.add(Property.forName(""id"").notIn(subselect));return this.getSession().createCriteria(Course.class).add(Property.forName(""id"").notIn(subselect)).list();

at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:362)
at org.hibernate.criterion.SubqueryExpression.createAndSetInnerQuery(SubqueryExpression.java:153)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:69)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:380)
at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:113)
at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.(CriteriaLoader.java:92)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1697)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at com.esmis.dao.impl.CourseDaoImpl.findSchoolYearCourses(CourseDaoImpl.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy7.findSchoolYearCourses(Unknown Source)
at com.esmis.service.impl.CourseServiceImpl.getSchoolYearCourse(CourseServiceImpl.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.esmis.filter.TimeOutFilter.doFilter(TimeOutFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2440)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2429)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

时间: 2025-01-28 15:43:47

detachedcriteria-Hiberate 用detached作子查询 报空指针异常的相关文章

sqlserver子查询报错

  sqlserver跟oracle对比,如果涉及到的子查询,则相应的表名.字段就必须命名一个别名才能执行.主要有两种情况: 1.查询sql里面只有简单子查询不包含分组.求和等待 eg:elect * from (select com_id from company) 如此会报错,必须加上外层加上别名,里层的select * from company这里可以加别名,也可以不加正确:select * from ( select com_id from company) a 2.查询的sql里面包含

sql:除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询

执行sql语句: select * from ( select * from tab where ID>20 order by userID desc ) as a order by date desc 逻辑上看着挺对 但是报错: 除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图.内联函数.派生表.子查询和公用表表达式中无效. 只要我们在嵌套子查询视图里面加入: top 100 percent 即可 select * from ( select top 100 p

sql子查询中列别名在主查询中无效

问题描述 sql子查询中列别名在主查询中无效 CREATE PROCEDURE dbo.query_test( @i_begin_time varchar(128) IN, /* 开始时间 / @i_end_time varchar(128) IN, / 结束时间 / @i_bussiness_tpe varchar(512) IN, / 类型 ) as declare @v_sql varchar(16384)/* 定义 需要执行的sql / declare @Rtime varchar(12

SQL子查询实例

  SQL子查询实例介绍: 子查询是在一个查询内的查询.子查询的结果被DBMS使用来决定包含这个子查询的高级查询的结果.在子查询的最简单的形式中,子查询呈现在另一条SQL语句的WHERE或HAVING子局内. 列出其销售目标超过各个销售人员定额综合的销售点. SELECT CITY FROM OFFICES WHERE TARGET > (SELECT SUM(QUOTA) FROM SALESREPS WHERE REP_OFFICES = OFFICE) SQL子查询一般作为WHERE子句或

标识符-一个关于子查询的问题求解决!

问题描述 一个关于子查询的问题求解决! SELECT CASE ????????? WHEN T1.A = T2.A THEN ?????????? (SELECT T3.A FROM (SELECT 1 AS A FROM DUAL) T3 WHERE T2.A = T3.A) ????????? ELSE ?????????? 0 ??????? END AS TEST ?? FROM (SELECT 1 AS A FROM DUAL) T1, (SELECT 1 AS A FROM DUA

select-mybatis 子查询 查不到对象是怎么回事

问题描述 mybatis 子查询 查不到对象是怎么回事 User 实体类中 加入了Role对象作为 User类的一个属性.Mapper如果这么去配置 Sql文中 加入连接Role表 可以查询出Role对象但是用如下方法却查询不到 是不是我什么地方写的有问题userMaper <!-- role是User类定义的一个属性--> <!-- javaType=""com.luxondata.entity.base.Role""> --> 解决

select-当子查询里面加上Chinese_PRC_CI_AS的排序规则后,某些数据却查不出来

问题描述 当子查询里面加上Chinese_PRC_CI_AS的排序规则后,某些数据却查不出来 代码如下: SELECT * from dbo.VW_msSyInfo_zy WHERE syh collate Chinese_PRC_CI_AS not in (select Syh from dbo.msSyInfo_zy) and indate >'2015-01-01' 当没加collate Chinese_PRC_CI_AS的时候会报错 无法解决 equal to 运算中 "Chine

MySQL中IN子查询会导致无法使用索引

原文:MySQL中IN子查询会导致无法使用索引   今天看到一个博客园的一篇关于MySQL的IN子查询优化的案例,一开始感觉有点半信半疑(如果是换做在SQL Server中,这种情况是绝对不可能的,后面会做一个简单的测试.)随后动手按照他说的做了一个表来测试验证,发现MySQL的IN子查询做的不好,确实会导致无法使用索引的情况(IN子查询无法使用所以,场景是MySQL,截止的版本是5.7.18) MySQL的测试环境 测试表如下 create table test_table2 ( id int

select-oracle 子查询中有两个字段,怎么同时查出来

问题描述 oracle 子查询中有两个字段,怎么同时查出来 比如说:select a.id,a.name,(select sum(b.count),a.num-sum(b.count) from b) from a; 有这么一个语句,我想一下在b表里查出两个值来,作为两列字段跟a.id a.name两列的值同时都显示出来,但是我上面的写法会报错.不知道括号里的情况该怎么处理? ps:当然我只是举了个例子,具体的语句要比这个复杂的多,求指点 解决方案 select a.id,a.name,c.co