开发者

QueryHint "ResultSetType.ForwardOnly" fails with Spring JPA/EclipseLink

开发者 https://www.devze.com 2023-02-16 16:00 出处:网络
I am facing a problem when setting q.setHint(QueryHints.RESULT_SET_TYPE, ResultSetType.ForwardOnly); for SQL query. I want to use this hint because I expect a large result set and want to avoid mem

I am facing a problem when setting

q.setHint(QueryHints.RESULT_SET_TYPE, ResultSetType.ForwardOnly);

for SQL query. I want to use this hint because I expect a large result set and want to avoid memory problems. I am using Spring JPA in combination with EclipseLink. The stack trace is

Exception [EclipseLink-6057] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.QueryException  Exception Description: The method [getContainerClass()] is not a valid method to call on object [ScrollableCursorPolicy(page size = 10)].
org.eclipse.persistence.exceptions.QueryException.methodNotValid(QueryException.java:774)
org.eclipse.persistence.internal.queries.ContainerPolicy.getContainerClass(ContainerPolicy.java:477)
org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:558)
com.App.core.geo.JpaGeoDao.getAllGeoNames(JpaGeoDao.java:101)
com.App.core.geo.GeoEngineBeanImpl.createLuceneIndex(GeoEngineBeanImpl.java:67)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy196.createLuceneIndex(Unknown Source)
com.App.core.main.beans.CachingBeanImpl.createTestActivityRate(CachingBeanImpl.java:512)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy207.createTestActivityRate(Unknown Source)
com.App.core.webinterface.beans.BatchBeanImpl.createTestActivityRate(BatchBeanImpl.java:50)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

The related method "getAllGeoNames" is implemented as follows:

    public List<GeoName> getAllGeoNames() {

    Query q = jpaTemplate.getEntityManagerFactory().createEntityManager().createQuery("SELECT g FROM GeoName g");
    q.setHint(QueryHints.JDBC_FETCH_SIZE, 1000000);

    q.setHint(QueryHints.RESULT_SET_TYPE, ResultSetType.ForwardOnly);

    List<GeoName> result = q.getResultList();

    return result;
}

The beans.xml is:

<tx:annotation-driven />

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityManagerFactor开发者_如何转开发yBean">
    <property name="persistenceUnitName" value="appGeoPU" />
    <!-- <property name="dataSource" ref="dataSource" /> -->
    <property name="jpaVendorAdapter">
        <bean id="jpaVendorAdapter"
            class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
            p:databasePlatform="org.eclipse.persistence.platform.database.PostgreSQLPlatform"
            p:showSql="true" p:generateDdl="true" />
    </property>
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
    </property>
</bean>

<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="geoDao" class="com.app.core.geo.JpaGeoDao">
    <property name="jpaTemplate" ref="jpaTemplate" />
</bean>

Is someone able to help me with this issue?

Cheers, Steffen


Have you tried using getSingleResult instead of getResultList, as you are setting a single scrollable cursor to be returned instead of a List.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号