需要执行两次ResultSet才能正常工作

时间:2014-08-29 08:31:47

标签: java mysql hibernate

我对Hibernate有一个奇怪的问题,当我尝试对必须返回集合的MySQL数据库执行查询时,Hibernate给我错误“无法提取ResultSet”。奇怪的是,当我使用Eclipse显示检查查询时,在执行此操作后,我继续正常流程,查询成功执行。所以似乎有必要两次执行它。

失败的行是“Collection res = query.getResultList();”

有什么想法吗?谢谢!

    public Collection getByCriteria(String criteria, Collection params) {
    try {
        if (params != null) {
            Iterator itParams;
            itParams = params.iterator();
            Query query = em.createQuery(criteria).setHint("org.hibernate.cacheable", true);
            //query.setHint("toplink.refresh", "true");
            for (int i = 0; itParams.hasNext(); i++) {
                query.setParameter(i + 1, itParams.next());
            }
            Collection res = query.getResultList();
            return res;
        } else {
            Query query = em.createQuery(criteria).setHint("org.hibernate.cacheable", true);
            Collection res = query.getResultList();
            return res;
        }

    } catch (Exception ee) {
        ee.printStackTrace();
    }
    return null;
}

堆栈跟踪是:

  javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
    at es.indra.inbase.common.crudBBDD.ManagerBBDDImpl.getByCriteria(ManagerBBDDImpl.java:150)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

(etc.)

0 个答案:

没有答案