0

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)
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
grep
  • 5,465
  • 12
  • 60
  • 112
  • 1
    Using mode aspectj requires either compile or load-time weaving. It isn't a simple matter of toggling the mode it requires more. – M. Deinum Nov 03 '15 at 14:12
  • I found tutorials, they do not use any weaving. https://hop2croft.wordpress.com/2011/07/06/jpa-basic-example-with-entitymanager-spring-and-maven/ – grep Nov 03 '15 at 15:07
  • 1
    Yes they do... That is enabled by the `spring-configured` tag as that also requires weaving. It will not work without weaving else you have to use proxies. – M. Deinum Nov 03 '15 at 19:07
  • is spring-configured annotation enough? What does it do? Do not I need to implement my Aspects (before/after method execution?) and etc? – grep Nov 04 '15 at 09:55
  • You don't need to implement anything... You need to either use compile time weaving for the spring aspects or lead-time... – M. Deinum Nov 04 '15 at 10:52
  • if i change proxy to aspectJ what differences will I have to transactions? Only the one, which problem I had? – grep Nov 11 '15 at 14:50

0 Answers0