Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring hibernate查询中的日期_Java_Spring_Hibernate_Jpa_Jpql - Fatal编程技术网

Java spring hibernate查询中的日期

Java spring hibernate查询中的日期,java,spring,hibernate,jpa,jpql,Java,Spring,Hibernate,Jpa,Jpql,我有一种从数据库中获取教育事件的方法。不知道它为什么不能运行。似乎查询只在某些情况下失败,但无法真正找到破坏它的输入参数。我无法从日志中获得任何关于1853位置语法错误的提示。您是否知道问题的原因或如何进一步调试该方法 public List<EE> findEEs(S s, List<EM> eMs, E e) { TypedQuery<EE> query = entityManager.createQuery( "select di

我有一种从数据库中获取教育事件的方法。不知道它为什么不能运行。似乎查询只在某些情况下失败,但无法真正找到破坏它的输入参数。我无法从日志中获得任何关于1853位置语法错误的提示。您是否知道问题的原因或如何进一步调试该方法

public List<EE> findEEs(S s, List<EM> eMs, E e) {
    TypedQuery<EE> query = entityManager.createQuery(
        "select distinct ee from EE ee left join ee.lSE lse "
            + "where ee.eM in (:em) "
            + "and (ee.scope = :publicScope "
            + "or (ee.scope = :limitedScope and (ee.hE= :e or :e in lse)) "
            + "or (ee.scope = :localScope and ee.hE = :education)) "
            + "and ee.status = :status and ee.startDate > :now "
            + "and (ee.groupSize = 0 or (ee.groupSize > 0 "
            + "  and ee.groupSize > (ee.numberOfStudents + ee.reservedSeats))) "
            + "and ee.id not in (select pee.eE.id from PEE pee "
            + "where studentStatus.s = :s and eE.eM in (:em))",
        EE.class);

    query.setParameter("s", s);
    query.setParameter("em", eMs);
    query.setParameter("publicScope", PUBLIC);
    query.setParameter("limitedScope", LIMITED);
    query.setParameter("localScope", LOCAL);
    query.setParameter("e", e);
    query.setParameter("status", CONFIRMED);
    query.setParameter("now", new DateTime());

    return query.getResultList();

逗号分隔列表中必须至少有一个元素 定义IN表达式的值集

确保传入的参数至少有一个值


还可以查看一个相关的。

您确定:em参数从不为空吗?另外,您使用的是什么版本的hibernate?是>=3.6.1吗?请增加hibernate日志查询+绑定参数…对于一个失败的参数…我怀疑joda DateTime是罪魁祸首。@AbdullahKhan,实际上这是一个很好的观点。:em参数有时确实是空的,但是查询不应该返回空的结果列表而不是失败吗?@xerx593,我也有同样的怀疑,但是删除joda DateTime参数并没有改变任何事情。真正的查询和参数会有帮助…->@krltos-这对您有帮助吗!?
2017-10-19 14:46:32,673 [http-nio-8090-exec-10] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42601
2017-10-19 14:46:32,674 [http-nio-8090-exec-10] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: syntax error at or near ")"
  Position: 1853
lokakuuta 19, 2017 2:46:32 IP. org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver logException
WARNING: Resolved exception caused by Handler execution: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

Data access failure

Sorry, a problem occurred while accessing the database.

org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384)
org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:246)
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491)
org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
com.sun.proxy.$Proxy435.findUnaddedEducationEvents(Unknown Source)