我在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;
}
问题是它实际上在工作,但有时它会在getResultList()中崩溃并抛出这个:
是因为方法生成的List的类型?无论如何,工作查询和崩溃查询之间没有太大区别。我的意思是他们都或多或少有相同数量的结果。
有什么建议么?
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)
编辑以增加精度:
如果我更深入地调试一下,我会看到抛出异常的方法
类 org.springframework.orm.jpa.SharedEntityManagerCreator.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);