javax.persistence.TransactionRequiredException:Executing an update/delete query
at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:409)
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1601)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:409)
at com.sun.proxy.$Proxy243.executeUpdate(UnknownSource)
at bynear.web.service.RequirementInsertService.replyOldToNewSite(RequirementInsertService.java:417)
at bynear.web.service.RequirementInsertService.ss(RequirementInsertService.java:509)
at bynear.web.service.RequirementInsertService$$FastClassBySpringCGLIB$$ff41465b.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:685)
publicclassRequirementInsertService{@AutowiredDemandOutService demandOutService;@Transactional@ModifyingpublicvoidreplyOldToNewSite(){String ss="INSERT INTO demandout ...."//需要用这种才不会报错
demandOutService.insertDemandout(insertsql);//如果执行下面这段会报错//entityManager.createNativeQuery(insertsql).executeUpdate();//执行插入语句}}publicclassDemandOutService{@Transactional@ModifyingpublicvoidinsertDemandout(){
entityManager.createNativeQuery(insertsql).executeUpdate();//执行插入语句}}
javax.persistence.TransactionRequiredException: Executing an update/delete query
javax.persistence.TransactionRequiredException: Executing an update/delete query at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:409) at org.hibernate.query.internal.Abst