我对坚持在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);