简体   繁体   English

@NamedStoredProcedureQuery与Spring Data JPA Repository - Type不能为null错误

[英]@NamedStoredProcedureQuery with Spring Data JPA Repository - Type cannot be null error

I have a JPA Entity class RequestSummary which originally was being populated from a database view. 我有一个JPA实体类RequestSummary,它最初是从数据库视图中填充的。 I'm trying to refactor this to use a stored procedure for performance reasons but am having issues getting it set up correctly. 我正在尝试重构此操作以出于性能原因使用存储过程但是在设置正确时遇到问题。

I have a stored procedure 'sp_bsc_request_summary' which takes a staffId as a parameter. 我有一个存储过程'sp_bsc_request_summary',它将staffId作为参数。

My spring data repository looks like this 我的spring数据存储库看起来像这样

public interface RequestSummaryRepository extends JpaRepository<RequestSummary, Long> {

@Procedure("procedureFindAll")
public List<RequestSummary> procedureFindAll(@Param("staffId") Long staffId);
}

My JPA Entity looks like this... 我的JPA实体看起来像这样......

@Entity
@Table(name = "vw_bsc_request_summary")
@NamedStoredProcedureQuery(
    name = "procedureFindAll", 
    procedureName = "sp_bsc_request_summary", 
    resultClasses = {RequestSummary.class}, 
    parameters = {@StoredProcedureParameter(mode = ParameterMode.IN, type = Long.class, name = "staffId")})

public class RequestSummary {

    @Id
    @Column(name = "bsc_request_id")
    private Long id;
    ....etc 

So there are a few things I'm not sure of 所以有一些我不确定的事情

  • The entity is no longer backed by the 'vw_bsc_request_summary', so do I completely remove the @Table annotation? 该实体不再受'vw_bsc_request_summary'的支持,所以我是否完全删除@Table注释? If I do then JPA complains about not being able to find a table with the default name RequestSummary 如果我这样做,那么JPA抱怨无法找到一个默认名称为RequestSummary的表
  • Should I be including the @Entity annotation if this entity is not backed by a table or view? 如果此实体没有表或视图支持,我是否应该包含@Entity注释?

With the code above, when I try and run an integration test to call the method 使用上面的代码,当我尝试运行集成测试来调用该方法时

@Test
public void testFindAll() {
    final List<RequestSummary> requests = this.summaryRepo.procedureFindAll(61953104L);
    Assert.assertNotNull(requests);
    Assert.assertTrue(requests.size() > 0);
}

Then I get a stacktrace complaining about a null HibernateType 然后我得到一个抱怨null HibernateType的stacktrace

org.springframework.dao.InvalidDataAccessApiUsageException: Type cannot be null; nested exception is java.lang.IllegalArgumentException: Type cannot be null
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:381)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:157)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy54.procedureFindAll(Unknown Source)
    at com.hsbc.gbgcf.bsc.repository.RequestRepositoryIntegrationTest.testFindAll(RequestRepositoryIntegrationTest.java:111)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: Type cannot be null
    at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.setHibernateType(AbstractParameterRegistrationImpl.java:182)
    at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:131)
    at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:140)
    at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:97)
    at org.hibernate.procedure.internal.NamedParameterRegistration.<init>(NamedParameterRegistration.java:41)
    at org.hibernate.procedure.internal.ProcedureCallImpl.registerParameter(ProcedureCallImpl.java:344)
    at org.hibernate.jpa.internal.StoredProcedureQueryImpl.registerStoredProcedureParameter(StoredProcedureQueryImpl.java:152)
    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.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:362)
    at com.sun.proxy.$Proxy68.registerStoredProcedureParameter(Unknown Source)
    at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.newAdhocStoredProcedureQuery(StoredProcedureJpaQuery.java:175)
    at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.createStoredProcedure(StoredProcedureJpaQuery.java:130)
    at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.doCreateQuery(StoredProcedureJpaQuery.java:89)
    at org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery.createQuery(StoredProcedureJpaQuery.java:80)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$ProcedureExecution.doExecute(JpaQueryExecution.java:298)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:77)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:100)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:91)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:393)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:371)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    ... 37 more

I've looked at numerous other posts and at the Spring.io documentation but I'm still struggling to resolve this. 我看过很多其他帖子和Spring.io文档,但我仍然在努力解决这个问题。

Any ideas? 有任何想法吗?

UPDATE UPDATE

So following suggestions from lanemax ...my service method looks like this: 所以根据lanemax的建议......我的服务方法如下:

public List<RequestSummary> findAll(final Long staffId) {
    final StoredProcedureQuery storedProcedureQuery = this.entityManager.createNamedStoredProcedureQuery("procedureFindAll");
    storedProcedureQuery.setParameter("staffId", staffId);
    storedProcedureQuery.execute();
    return storedProcedureQuery.getResultList();
}

and my entity class like this 和我的实体类一样

@NamedStoredProcedureQuery(name = "procedureFindAll", procedureName = "sp_bsc_request_summary", parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, type = Long.class, name = "staffId")}, resultSetMappings = "mapping")

@SqlResultSetMapping(name = "mapping", classes = {@ConstructorResult(targetClass = RequestSummary.class, columns = {
@ColumnResult(name = "bsc_request_id", type = Long.class), @ColumnResult(name = "created_date", type = Date.class),
@ColumnResult(name = "transaction_size", type = BigDecimal.class),
@ColumnResult(name = "approval_status_id", type = Long.class),
@ColumnResult(name = "approval_status_desc", type = String.class), @ColumnResult(name = "approval_key", type = String.class),
@ColumnResult(name = "captain_staff_id", type = Long.class), @ColumnResult(name = "captain_name", type = String.class),
@ColumnResult(name = "captain_country_id", type = Long.class), @ColumnResult(name = "captain_country", type = String.class),
@ColumnResult(name = "est_fee_usd", type = BigDecimal.class), @ColumnResult(name = "client_vision_id", type = String.class),
@ColumnResult(name = "client_full_name", type = String.class), @ColumnResult(name = "client_country_id", type = Long.class),
@ColumnResult(name = "country_description", type = String.class), @ColumnResult(name = "mastergroup", type = String.class),
@ColumnResult(name = "decision_staff_id", type = Long.class), @ColumnResult(name = "decision_staff_name", type = String.class),
@ColumnResult(name = "temporary_client_name", type = String.class)

})})
@Entity
public class RequestSummary {

@Id
private Long id;

When I call the method though I get a stack-trace as below 当我调用方法时,虽然我得到如下的堆栈跟踪

2016-12-16 10:58:10,565 ERROR [http-bio-8080-exec-28] controller.RequestController - Current CallableStatement ou was not a ResultSet, but getResultList was called
java.lang.IllegalStateException: Current CallableStatement ou was not a ResultSet, but getResultList was called
at org.hibernate.jpa.internal.StoredProcedureQueryImpl.getResultList(StoredProcedureQueryImpl.java:336)
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.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:362)
at com.sun.proxy.$Proxy82.getResultList(Unknown Source)
at com.company.gbgcf.bsc.service.RequestService.findAll(RequestService.java:112)
at com.company.gbgcf.bsc.service.RequestService.findAll(RequestService.java:125)
at com.company.gbgcf.bsc.controller.RequestController.findAllRequests(RequestController.java:102)
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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:747)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:676)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at com.company.gbgcf.bsc.filters.AuthenticatedSessionFilter.doFilter(AuthenticatedSessionFilter.java:143)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)

Initially I thought this might be because the procedure was printing out some debug info as well asthe recordset, however having removed these print statements I am still getting the same error..... 最初我认为这可能是因为程序打印出一些调试信息以及记录集,但是删除了这些打印语句我仍然得到同样的错误.....

UPDATE 2 更新2

Adding a bit more logging confirms that the correct procedure is called and the parameter is bound... 添加更多日志记录确认调用了正确的过程并且参数已绑定...

    2016-12-16 11:54:53,883 DEBUG [http-bio-8080-exec-25] spi.SqlStatementLogger - 
    {call sp_bsc_request_summary(?)}
    Hibernate: 
    {call sp_bsc_request_summary(?)}
    2016-12-16 11:54:53,904 TRACE [http-bio-8080-exec-25] sql.BasicBinder - binding parameter [1] as [BIGINT] - [61953104]
2016-12-16 11:54:53,984 DEBUG [http-bio-8080-exec-1] annotation.AbstractMessageConverterMethodProcessor - Written [{"forename":"CRAIG","surname":"GORDON","roleNames":["DP_DEFAULT_VIEW_LAF","DP_MENU_DELETE","GB_ADVISORY_DEAL_STATUS_UPDATE_REPORT_USER","DP_ADD_NEW_DEAL","DP_CF_Report","GB_CAPITAL_FINANCING_REPORT","LAF_MD_PIPELINE_REPORT_USER","LAF_CANNED_REPORT","DCM_DEAL_PIPELINE_USER","DP_DEAL_PIPELINE_USER","GB_ADVISORY_NEW_DEALS_REPORT_USER","LAF_DEAL_CLOSE_REPORT","DP_SHOW_CLIENT_ON_REPORTS","DCM_CAPITAL_FINANCING_REPORT","LAF_DEAL_PIPELINE_USER","GB_CANNED_REPORT","DP_EXT_Deal_Access_DCM","GB_DEAL_PIPELINE_USER","Clone_GB_Deal","DP_EXT_Deal_Access_MnA"]}] as "application/json;charset=UTF-8" using [org.springframework.http.converter.StringHttpMessageConverter@d3d0bbc]
2016-12-16 11:54:53,986 DEBUG [http-bio-8080-exec-1] servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'bsc': assuming HandlerAdapter completed request handling
2016-12-16 11:54:53,986 DEBUG [http-bio-8080-exec-1] servlet.FrameworkServlet - Successfully completed request
2016-12-16 11:54:53,988 DEBUG [http-bio-8080-exec-1] access.ExceptionTranslationFilter - Chain processed normally
2016-12-16 11:54:53,988 DEBUG [http-bio-8080-exec-1] context.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
Building Return [isResultSet=false, updateCount=0, extendedReturn=false
2016-12-16 11:54:54,597 DEBUG [http-bio-8080-exec-25] jpa.EntityManagerFactoryUtils - Closing JPA EntityManager
2016-12-16 11:54:54,617 ERROR [http-bio-8080-exec-25] controller.RequestController - Current CallableStatement ou was not a ResultSet, but getResultList was called
java.lang.IllegalStateException: Current CallableStatement ou was not a ResultSet, but getResultList was called
    at org.hibernate.jpa.internal.StoredProcedureQueryImpl.getResultList(StoredProcedureQueryImpl.java:336)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

UPDATE 3 更新3

Finally got this working. 终于搞定了这个。 So for anyone else experiencing issues.... The error - Current CallableStatement ou was not a ResultSet was resolved by including set nocount on in my stored procedure (this is in sybase 15) This then left me with another error where the @ConstructorResult could not locate the correct constructor. 所以对于遇到问题的其他人....错误 - Current CallableStatement ou was not a ResultSet通过在我的存储过程中包含set nocount on来解决(这是在sybase 15中)然后这给我留下了另一个错误,其中@ConstructorResult可以找不到正确的构造函数。 This was because some of the data types inferred from the fields returned from the procedure did not macth with those expected by the constructor. 这是因为从过程返回的字段中推断出的某些数据类型与构造函数所期望的数据类型不同。 Identifying the culprits involved downloading the hibernate source jar and putting a breakpoint on 确定下载hibernate源jar并设置断点的罪魁祸首

ConstructorResultColumnProcessor.resolveConstructor(Class targetClass, List<Type> types)

Once the types were aligned it all worked as expected. 一旦这些类型对齐,它就会按预期工作。

We ran into this a couple months ago and unfortunately, could not find a solution to it. 几个月前我们碰到了这个问题,不幸的是,找不到它的解决方案。 What we did, and you probably could too, was to create a service, inject the entity manager, and call it from there. 我们所做的,你可能也是,也就是创建一个服务,注入实体管理器,并从那里调用它。 It's not optimal, but like you, we fought trying to get a pure spring-data-jpa solution. 这不是最优的,但是和你一样,我们努力争取获得纯粹的spring-data-jpa解决方案。 If you want to go down this path, here's a solution that should work for you. 如果您想沿着这条路走下去,这里有一个适合您的解决方案。

Change your Entity definition a bit to 将您的实体定义更改为

@NamedStoredProcedureQuery(name = "procedureFindAll", 
   procedureName = "sp_bsc_request_summary", 
   parameters = {
     @StoredProcedureParameter(mode = ParameterMode.IN, type = Long.class, name = "staffId")},
   ,resultSetMappings = "mapping"))
@SqlResultSetMapping(name = "mapping", classes = {
   @ConstructorResult(targetClass = RequestSummary.class, columns = {               
      @ColumnResult(name = "bsc_request_id", type = Long.class)
   })
})

Above, add a ColumnResult for each field you want mapped. 在上面,为要映射的每个字段添加ColumnResult。 Your service will look like this 您的服务将如下所示

...
@Autowired
private EntityManager entityManager;

public List<RequestSummary> findAll(Long staffId) {
   StoredProcedureQuery storedProcedureQuery = entityManager.createNamedStoredProcedureQuery("sp_bsc_request_summary");
   storedProcedureQuery.setParameter("staffId", staffId);
   storedProcedureQuery.execute();
   return storedProcedureQuery.getResultList();
}

I came across this issue before. 我之前遇到过这个问题。 First the @Procedure did not work. 首先@Procedure不起作用。 So I went with @NamedStoredProcedureQuery . 所以我选择@NamedStoredProcedureQuery That works but I just find it a lot of plumbing or boiler plate codes. 这是有效的,但我发现很多管道或锅炉板代码。 My elegant/concise solution was to use the nativeQuery . 我优雅/简洁的解决方案是使用nativeQuery Trying to mimic your code above, my solution for it will look like this: 试图模仿上面的代码,我的解决方案将如下所示:

public interface ProcedureFindAll extends JpaRepository<RequestSummary, Long> {

    @Query(value = "EXECUTE sp_bsc_request_summary :staffId", nativeQuery = true)
    List<RequestSummary> findAllRequestSummary( @Param( "staffId" ) Long staffId);
}

And your entity will just have the Entity annotation. 而您的实体将只有实体注释。

@Entity
public class RequestSummary {

    @Id
    private Long id;
    //...code remove for brevity
}

The solution from here worked for me: Change 这里的解决方案对我有用:改变

public List<RequestSummary> findAll(final Long staffId) {...

to

public Object[] findAll(final Long staffId) {...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Data JPA NamedStoredProcedureQuery 多个输出参数 - Spring Data JPA NamedStoredProcedureQuery Multiple Out Parameters JPA 2.1-@NamedStoredProcedureQuery-ParameterMode.IN-空值给出错误 - JPA 2.1 - @NamedStoredProcedureQuery - ParameterMode.IN - null value gives error Spring Data JPA Repository findAll() 空指针 - Spring Data JPA Repository findAll() Null Pointer Spring 数据 JPA - 存储库返回不同的类型 - Spring Data JPA - repository returns different type Spring 数据 JPA:CreationDate 不能是 null - Spring Data JPA: CreationDate cannot be null 在 Spring 4 JPA Hibernate 5 中对 @NamedStoredProcedureQuery 的过程使用架构 - Using schema for Procedure on @NamedStoredProcedureQuery in Spring 4 JPA Hibernate 5 尝试使用Spring Data JPA创建自定义存储库时,找不到类型错误的属性 - No property found for type error when try to create custom repository with Spring Data JPA JPA 2.1错误:找不到具有该名称的@NamedStoredProcedureQuery: - JPA 2.1 error : No @NamedStoredProcedureQuery was found with that name : Spring JPA 中 NamedStoredProcedureQuery 中的错误 - “找到与位置参数关联的命名存储过程参数” - Error in NamedStoredProcedureQuery in Spring JPA - “Found named stored procedure parameter associated with positional parameters” Generic Spring Data JPA存储库实现,用于按类类型加载数据 - Generic Spring Data JPA repository implementation to load data by class type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM