English 中文(简体)
实体管理器中的 Arraindex out out of Bounds 例外 。 getResultList ()
原标题:ArrayIndexOutOfBoundsException in EntityManager..getResultList()

我对坚持在java有问题。

这是破例的方法

public List<EscaleCatalogueKaravel> obtenirListeEscalesCroisiereAvecIdCroisiereKaravel(Integer idCroisiereKaravel, Integer refLangue) {
         List<EscaleCatalogueKaravel> listeEscales = entityManager.createQuery("select p from EscaleCatalogueKaravel p " +
                    "where p.idCroisiereComplete=:idCroisiereComplete and p.refLangue=:refLangue")
                    .setParameter("idCroisiereComplete", idCroisiereKaravel)
                    .setParameter("refLangue", refLangue)
                    .getResultList();

         if (listeEscales == null || listeEscales.size() == 0) {
            return null;
         }

         return listeEscales;
    }

问题在于它实际上起作用了, 但有时它撞倒在“ 坚固的” ResultList () < /坚固的” 上,

这是因为该方法生成的清单类型? 总之,工作查询和崩溃查询之间没有很大区别。我的意思是,所有查询的结果或多或少相同。

有什么建议吗?

java.lang.ArrayIndexOutOfBoundsException: 1
    at com.mysql.jdbc.StringUtils.getInt(StringUtils.java:702)
    at com.mysql.jdbc.StringUtils.getInt(StringUtils.java:771)
    at com.mysql.jdbc.ByteArrayRow.getInt(ByteArrayRow.java:109)
    at com.mysql.jdbc.ResultSetImpl.getIntWithOverflowCheck(ResultSetImpl.java:7209)
    at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2699)
    at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2814)
    at org.hibernate.type.IntegerType.get(IntegerType.java:28)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
    at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2101)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
    at org.hibernate.loader.Loader.getRow(Loader.java:1206)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
    at org.hibernate.loader.Loader.doQuery(Loader.java:701)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2213)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:310)
    at $Proxy33.getResultList(Unknown Source)
    at com.karavel.connectivity.gateway.croisiere.common.repository.impl.CatalogueKaravelRepositoryImpl.obtenirIdCroisiereCompleteAvecInfoCroisiere(CatalogueKaravelRepositoryImpl.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    at $Proxy23.obtenirIdCroisiereCompleteAvecInfoCroisiere(Unknown Source)
    at com.karavel.connectivity.gateway.croisiere.controller.service.RechercherCroisiereController.getItineraireCroisiere(RechercherCroisiereController.java:378)
    at com.karavel.connectivity.gateway.croisiere.controller.service.RechercherCroisiereController.obtenirListeCroisiere(RechercherCroisiereController.java:283)

添加更精确的 EDIT:

如果我把垃圾调得更深一点, 我看到了扔破例的方法

< 坚固> lass org. spring framerform.orm.jpa. 共享实体管理创建器.java

private static class DeferredQueryInvocationHandler implements InvocationHandler {

        private final Query target;

        private final EntityManager em;

        public DeferredQueryInvocationHandler(Query target, EntityManager em) {
            this.target = target;
            this.em = em;
        }

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            // Invocation on Query interface coming in...

            if (method.getName().equals("equals")) {
                // Only consider equal when proxies are identical.
                return (proxy == args[0]);
            }
            else if (method.getName().equals("hashCode")) {
                // Use hashCode of EntityManager proxy.
                return hashCode();
            }
            else if (method.getName().equals("unwrap")) {
                // Handle JPA 2.0 unwrap method - could be a proxy match.
                Class targetClass = (Class) args[0];
                if (targetClass == null || targetClass.isInstance(proxy)) {
                    return proxy;
                }
            }

            // Invoke method on actual Query object.
            try {
                Object retVal = method.invoke(this.target, args);
                return (retVal == this.target ? proxy : retVal);
            }
            catch (InvocationTargetException ex) {
                throw ex.getTargetException();
            }
            finally {
                if (method.getName().equals("getResultList") || method.getName().equals("getSingleResult") ||
                        method.getName().equals("executeUpdate")) {
                    EntityManagerFactoryUtils.closeEntityManager(this.em);
                }
            }
        }
    }

确切地说:

Object retVal = method.invoke(this.target, args); 
问题回答

我唯一能想到的是, 您的列表不是空的, 包含一个元素 。 在此情况下, 数组. get(1) 将造成错误, 如数组. get( 0) 是第一个元素 。 也许您可以记录数组大小, 并查看其大小是否符合您的期望 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签