I have a spring application which works with hibernate and annotations.
A class X (that is outside the Spring context) acessing a class Y (that is in the Spring context).
This first communication I solved using a class that implements ApplicationContextAware according to this Stack Overflow aswer
How to access a method a Spring Bean from a class not in the Spring Container
The class Y injects a @Service class Z that persist information in the database (and it has a @Transactional annotation in the method that persists the information).
The problem is that when a call from Y calls Z.merge() (x -> Y -> Z.merge()), the following exception occurs:
Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'merge' call
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:282)
at com.sun.proxy.$Proxy48.merge(Unknown Source)
Is there any possibility for this work? I am usign Spring 4.3.3