I have service layer like this:
@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()
}
}
with this config:
<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>
Everything woks fine! Because of I have proxy based transaction, new transaction is not created in method B()! But one transaction is created well! Everything is logically!
But what about this?
<tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" />
This should fix my problem, new transaction must be created! but I have such error:
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)