首页 > 编程知识 正文

enablescheduling注解,qualifier注解

时间:2023-05-06 07:07:49 阅读:106035 作者:1075

现象说明dao层代码如下

@ modifying @ query (value=' insert into t _ P5 _ blog _ link _ his (click _ hit,release_time,url,source,tititity ) 1000000000000 ',native query=true (publicvoidtransferhis );控制台错误如下

org.spring framework.Dao.invaliddataaccessapiusageexception : executinganupdate/delete query; nestedexceptionisjavax.persistence.transactionrequiredexception : executinganupdate/eletequeryatorg.spring framework.ORM.JPA.entitymanagerfactoryutils.convertjpaaccessexceptionifpossible (atorg.sprile ) pa dialect.translateexceptionifpossible (hibernatejpadialect.Java atorg.spring framework.ORM.JPA.abstractentitymanage ible (atorg.spring framework.Dao.support.chainedpersistenceexceptiontranslator.translateeexceptionifpossible (9)9) atted ess utils.translateifnecessary (data access utils.Java 3360213 )。 atorg.spring framework.Dao.support.persistenceexceptiontranslationinterceptor.invoke (atorg.spring framework.AOP ) o ceed (reflectivemethodinvocation.Java 3360179 ) atorg.spring framework.data.JPA.repository.support.lockmoderepositorypostprocessor $ lockmodepopulatingmethodintercerchodinterce gframework.AOP.framework.reflectivemethodinvocation.proceed (reflectivemethodinnned ) )。 atorg.spring framework.AOP.interceptor.exposeinvocationinterceptor.invoke (exposeinvocationinterceptor.Java 336092 ava ) flectivemethodinvocation.proceed (reflectivemethodinvocation.Java 3360179 ) atorg.spring framework.AOP.framework.jdd atcom.sun.proxy.$ proxy 29.updatepersonemailbylastname (unknown source ) atcom.Liwei.spring data.service.persons

(PersonService.java:15) at com.liwei.springdata.test.DataSourceTest.testUsingModifingAnnotation(DataSourceTest.java:154) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 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:670) 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: javax.persistence.TransactionRequiredException: Executing an update/delete query at org.hibernate.jpa.spi.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:362) at com.sun.proxy.$Proxy31.executeUpdate(Unknown Source) at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:174) at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:61) at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:95) at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:85) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:323) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ... 32 more

问题分析

解决方法如下

@EnableTransactionManagement@SpringBootApplicationpublic class P5Application@Transactional public void transferHis() { try { blogLinkHisRepository.transferHis(); } catch (Exception e) { logger.error("不合格的博客转入历史表异常!", e); } }

jpa有这个问题,mybatis不存在这个问题
谢谢大家,多多指教!!!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。