Java 在Spring服务中持久化会导致TransactionRequiredException

Java 在Spring服务中持久化会导致TransactionRequiredException,java,spring,jpa,openjpa,Java,Spring,Jpa,Openjpa,由于某些原因,在Spring服务中持久化会导致TransactionRequiredException 我不确定我应该为这个问题包含多少信息,所以如果需要,我可以添加信息。我有一个Spring服务,它扩展了事务管理的抽象类 如果我在方法中保存,我将得到org.apache.rename.openjpa.persistence.TransactionRequiredException 即使我为方法指定了@Transactional 通过调用服务类外部的服务调用相同的方法可以正常工作 我的方法: @

由于某些原因,在Spring服务中持久化会导致TransactionRequiredException

我不确定我应该为这个问题包含多少信息,所以如果需要,我可以添加信息。我有一个Spring服务,它扩展了事务管理的抽象类

如果我在方法中保存,我将得到org.apache.rename.openjpa.persistence.TransactionRequiredException

即使我为方法指定了@Transactional

通过调用服务类外部的服务调用相同的方法可以正常工作

我的方法:

@Service("PriceListLookupService")
public class PriceListLookupServiceImpl extends
    AbstractEpEntityService<PriceList> implements
    PriceListLookupService {
@Override
@Transactional
public PriceList createPriceListForCatalogStore(String catalogName,
        String storeName) {
    // Catalog catalog = catalogService.findByName(catalogName);
    try {
        PriceList priceList = new PriceList();
        this.saveOrUpdate(priceList);
    } catch (Exception e) {
        LOG.error("createDestinationPriceListError", e);
    }
    return null;
}
@Service(“PriceListLookupService”)
公共类PriceListLookupServiceImpl扩展
AbstracteEntityService实现
PriceListLookupService{
@凌驾
@交易的
public PriceList createPriceListForCatalogStore(字符串catalogName,
字符串(存储名){
//Catalog Catalog=catalogService.findByName(catalogName);
试一试{
PriceList PriceList=新的PriceList();
此.saveOrUpdate(价格表);
}捕获(例外e){
LOG.error(“createDestinationPriceListError”,e);
}
返回null;
}
抽象类

public abstract class AbstractEntityService<T, I> implements EntityService<T, I> {

@PersistenceContext
protected EntityManager entityManager;
protected Class<T> entityClass;


@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public T saveOrUpdate(T entity) {
    if(isEntityPersistent(entity)) {
        entity = entityManager.merge(entity);
    } else {
        entityManager.persist(entity);
    }
    entityManager.flush();
    return entity;
}
公共抽象类AbstractEntityService实现EntityService{
@持久上下文
受保护的实体管理器实体管理器;
保护类实体类;
@事务性(只读=false,传播=propagation.REQUIRED)
公共T存储或更新(T实体){
if(实体){
实体=entityManager.merge(实体);
}否则{
entityManager.persist(实体);
}
entityManager.flush();
返回实体;
}
例外情况:


org.apache.renamed.openjpa.persistence.TransactionRequiredException:要执行此操作,它必须在事务中写入,或者您的设置必须允许非事务性写入,并且不能分离所有非事务性读取。

看起来,服务中第一个调用的方法应该具有@Transactional注释如果调用第一个方法A,该方法在服务内调用方法B,那么方法A必须具有@Transactional注释