简体   繁体   English

javax.persistence.TransactionRequiredException:当前没有活动的事务

[英]javax.persistence.TransactionRequiredException: There is no currently active transaction

I have Service with EntityManager and create DAO class in init method and pass EntityManager to DAO consctructor.: 我有EntityManager服务,并在init方法中创建了DAO类,然后将EntityManager传递给DAO构造器。

@Slf4j
public class OPhoneService {
@Setter
    private EntityManager entityManager;

public void init() {
        log.info("init");
        log.info(Thread.currentThread().getName());
        oPhoneDao = new OPhoneDaoImpl(entityManager);
        List<OPhone> oPhones = oPhoneDao.getAllOPhones(0);
        OPhone oPhone = oPhones.get(0);
        oPhone.setState(1);
        oPhoneDao.merge(oPhone);
}

}

and on this line oPhoneDao.merge(oPhone); 在这一行上, oPhoneDao.merge(oPhone); get error: 得到错误:

javax.persistence.TransactionRequiredException: There is no currently active transaction.

my merge method: 我的合并方法:

@Override
    public E merge(E e) {
        E merge = entityManager.merge(e);
        entityManager.flush();
        return merge;
    }

And my bean config 和我的bean配置

<bean id="oPhoneBean" class="....services.OPhoneService" init-method="init"
          scope="singleton">
        <jpa:context unitname="ophone" property="entityManager"/>
        <tx:transaction method="*" value="Required"/>
    </bean>

You need to start and commit transaction in your merge method. 您需要在merge方法中启动并提交事务。

@Override
public E merge(E e) {
    EntityTransaction tx = entityManager.getTransaction();
    tx.begin();
    E merge = entityManager.merge(e);
    tx.commit();
    entityManager.flush();
    return merge;
}

This is a known issue in Aries blueprint. 这是白羊座蓝图中的一个已知问题。 The transactional interceptor is not added to init methods. 事务拦截器未添加到init方法中。

See ARIES-1715 ARIES-1715

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.persistence.TransactionRequiredException:PuId =没有活动事务 - javax.persistence.TransactionRequiredException: No active transaction for PuId= 错误javax.persistence.TransactionRequiredException:没有事务正在进行 - Error javax.persistence.TransactionRequiredException: no transaction is in progress javax.persistence.TransactionRequiredException:Spring 5 中没有正在进行的事务 - javax.persistence.TransactionRequiredException: no transaction is in progress in Spring 5 javax.persistence.TransactionRequiredException: - javax.persistence.TransactionRequiredException: 没有正在进行的交易; 嵌套异常是 javax.persistence.TransactionRequiredException: no transaction is in progress - No transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress 为什么我的交易不活跃? javax.persistence.TransactionRequiredException:执行更新/删除查询 - Why is my transaction not active? javax.persistence.TransactionRequiredException: Executing an update/delete query 只读服务:javax.persistence.TransactionRequiredException:没有事务在进行中 - Read only service : javax.persistence.TransactionRequiredException: no transaction is in progress 在 Spring 启动应用程序中获取“javax.persistence.TransactionRequiredException:没有正在进行的事务” - Getting “javax.persistence.TransactionRequiredException: no transaction is in progress” in Spring Boot Application Hibernate JPA和Spring javax.persistence.TransactionRequiredException:没有事务正在进行中 - Hibernate JPA and Spring javax.persistence.TransactionRequiredException: no transaction is in progress javax.persistence.TransactionRequiredException:@Lock 注释上没有正在进行的事务 - javax.persistence.TransactionRequiredException: no transaction is in progress on @Lock annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM