为什么我在使用aspectJ模式事务时没有事务?

时间:2015-11-03 14:02:55

标签: spring spring-data-jpa spring-aspects

我有这样的服务层:

@Service
@Transactional
public class TransactionService {

    @Autowired
    private TransactionDao dao;


    @Transactional(propagation = Propagation.REQUIRED)
    public void A() {
        ...
        B();
    }
    @Transactional(propagation = Propagation.REQUIRED_NEW)
    public void B() {
        dao.save()
    }

}

使用此配置:

<property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<tx:annotation-driven transaction-manager="transactionManager" />
<property name="jpaProperties">
    <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
        <prop key="hibernate.show_sql">${show.sql}</prop>
        <prop key="hibernate.hbm2ddl.auto">${hbm2ddl.auto}</prop>
    </props>
</property>

         

一切都很好!由于我有基于代理的事务,因此不会在方法B()中创建新事务!但是创造了一笔交易!一切都是合乎逻辑的!

但是这个怎么样?

<tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" />

这应解决我的问题,必须创建新的交易!但我有这样的错误:

SEVERE: Servlet.service() for servlet [ name ] in context with path [/name-services] threw exception [Request processing failed; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available] with root cause
javax.persistence.TransactionRequiredException: No transactional EntityManager available
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:273)

0 个答案:

没有答案