我有一个方法:
package com.abc.pkg.service.db.impl;
public class OperationServiceImpl extends BaseService implements OperationService {
@Transactional
@Override
public String update(Operation operation,User user) {
BigDecimal count=(BigDecimal)em.createNativeQuery("select count(*) from RBMCORE.T_RBM_OPSCREENS_OPERATIONS where s_name= ? and id!= ?").setParameter(1, operation.getName()).setParameter(2, operation.getId()).getSingleResult();
if(count.intValue()>0)
return "This operation name is used by another operation. Please change it";
super.removeOpAppRelation(operation.getId(), -1);
Operation oldOperation=operationRepository.save(operation);
List<Operation> operations=new ArrayList<Operation>();
operations.add(operation);
}
}
而super.insertOpAppRelation方法内容为:
package com.abc.pkg.service.db.impl;
public abstract class BaseService {
@PersistenceContext
protected EntityManager em;
@Transactional
protected void removeOpAppRelation(int opId,int appId){
String sql="delete table a where 1=1";
if(opId>0)
sql+=" and op_id="+opId;
if(appId>0)
sql+=" and app_id="+appId;
em.createNativeQuery(sql).executeUpdate();
}
}
并触发 removeOpAppRelation 方法,抛出此异常:
javax.persistence.TransactionRequiredException:执行更新/删除查询
在我的 appcontext.xml 我有这些:
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:component-scan base-package="com.abc.pck"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="rbmDataSource"/>
<property name="packagesToScan" value="com.ttech.rbm.model"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">none</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
作为事务经理,我正在使用:
org.springframework.orm.jpa.JpaTransactionManager
有任何想法吗?跟继承有关系吗?