Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@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. 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.

My spring data repository looks like this

public interface RequestSummaryRepository extends JpaRepository<RequestSummary, Long> {

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

My JPA Entity looks like this...

@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? If I do then JPA complains about not being able to find a table with the default name RequestSummary
  • Should I be including the @Entity annotation if this entity is not backed by a table or view?

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

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.

Any ideas?

UPDATE

So following suggestions from lanemax...my service method looks like this:

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

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

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. 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

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

Once the types were aligned it all worked as expected.

like image 362
Craig Avatar asked Dec 15 '22 01:12

Craig


1 Answers

I came across this issue before. First the @Procedure did not work. So I went with @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. 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
}
like image 172
alltej Avatar answered Jan 23 '23 06:01

alltej