This is my @Repository
interface with the native query:
@Repository
public interface RecentPersonRepository extends JpaRepository<RecentPerson, Long>{
@Query(value = "select id, person_id, unique_sc_id, unique_c_id, person_first_name, person_last_name, viewed_date, dob from recent_person where person_id = ?1 order by viewed_date desc", nativeQuery = true)
List<RecentPerson> getRecentPersons(String adjusterId);
}
This method is called by another method that has a @Transactional
annotation. The call to getRecentPersons()
, in the inner working of Spring, calls setRollbackOnly(true)
causing the rest of the transaction to fail. The call to getRecentPersons()
actually completes and returns the correct results but when the transaction is committed later the method fails because the transaction was set to rollback during the query method.
Spring calls setRollbackOnly
somewhere where it is dealing with parameters but I am passing a single value to the method and the method actually completes even though it was set to rollback only causing the rest of the method to fail.
Is there something wrong with my query? Or is there a problem because it is native=true
or something?
Below is the exception that causes the rollback and the stacktrace that ends up calling setRollbackOnly
:
java.lang.IllegalArgumentException: No parameter with index : 1 was found within the query: ReadAllQuery(referenceClass=RecentPerson sql="select id, person_id, unique_sc_id, unique_c_id, person_first_name, person_last_name, viewed_date, dob from recent_person where person_id = ?1 order by viewed_date desc").
setRollbackOnly:862, QueryImpl (org.eclipse.persistence.internal.jpa)
getParameter:966, QueryImpl (org.eclipse.persistence.internal.jpa)
getBindingFor:80, StringQueryParameterBinder (org.springframework.data.jpa.repository.query)
bind:60, StringQueryParameterBinder (org.springframework.data.jpa.repository.query)
bind:101, ParameterBinder (org.springframework.data.jpa.repository.query)
bind:76, SpelExpressionStringQueryParameterBinder (org.springframework.data.jpa.repository.query)
bindAndPrepare:161, ParameterBinder (org.springframework.data.jpa.repository.query)
bindAndPrepare:152, ParameterBinder (org.springframework.data.jpa.repository.query)
doCreateQuery:81, AbstractStringBasedJpaQuery (org.springframework.data.jpa.repository.query)
createQuery:190, AbstractJpaQuery (org.springframework.data.jpa.repository.query)
doExecute:123, JpaQueryExecution$CollectionExecution (org.springframework.data.jpa.repository.query)
execute:87, JpaQueryExecution (org.springframework.data.jpa.repository.query)
doExecute:116, AbstractJpaQuery (org.springframework.data.jpa.repository.query)
execute:106, AbstractJpaQuery (org.springframework.data.jpa.repository.query)
doInvoke:492, RepositoryFactorySupport$QueryExecutorMethodInterceptor (org.springframework.data.repository.core.support)
invoke:475, RepositoryFactorySupport$QueryExecutorMethodInterceptor (org.springframework.data.repository.core.support)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:56, DefaultMethodInvokingMethodInterceptor (org.springframework.data.projection)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
proceedWithInvocation:99, TransactionInterceptor$1 (org.springframework.transaction.interceptor)
invokeWithinTransaction:282, TransactionAspectSupport (org.springframework.transaction.interceptor)
invoke:96, TransactionInterceptor (org.springframework.transaction.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:136, PersistenceExceptionTranslationInterceptor (org.springframework.dao.support)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:133, CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor (org.springframework.data.jpa.repository.support)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:92, ExposeInvocationInterceptor (org.springframework.aop.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:57, SurroundingTransactionDetectorMethodInterceptor (org.springframework.data.repository.core.support)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
invoke:213, JdkDynamicAopProxy (org.springframework.aop.framework)
getRecentPersons:-1, $Proxy193 (com.sun.proxy)
addRecentPerson:235, PersonService (com.blah.portal.services.web.service)
invoke:-1, PersonService$$FastClassBySpringCGLIB$$50ca8ee8 (com.blah.portal.services.web.service)
invoke:204, MethodProxy (org.springframework.cglib.proxy)
invokeJoinpoint:738, CglibAopProxy$CglibMethodInvocation (org.springframework.aop.framework)
proceed:157, ReflectiveMethodInvocation (org.springframework.aop.framework)
proceedWithInvocation:99, TransactionInterceptor$1 (org.springframework.transaction.interceptor)
invokeWithinTransaction:282, TransactionAspectSupport (org.springframework.transaction.interceptor)
invoke:96, TransactionInterceptor (org.springframework.transaction.interceptor)
proceed:179, ReflectiveMethodInvocation (org.springframework.aop.framework)
intercept:673, CglibAopProxy$DynamicAdvisedInterceptor (org.springframework.aop.framework)
addRecentPerson:-1, PersonService$$EnhancerBySpringCGLIB$$372034be (com.blah.portal.services.web.service)
addRecentPerson:49, PersonController (com.blah.portal.services.web.controller)
Versions
org.springframework.data:spring-data-commons:1.13.10.RELEASE
org.springframework.data:spring-data-jpa:1.11.10.RELEASE
org.eclipse.persistence:eclipselink:2.7.1
org.eclipse.persistence:javax.persistence:2.1.1
org.eclipse.persistence:org.eclipse.persistence.jpa:2.4.2
org.eclipse.persistence:org.eclipse.persistence.jpa.jpql:2.4.2