Hi there,
I need to deploy the app. to a J2EE container using JTA. So the annotation @Transactional does not work because it is using EntityTransaction, not compatible with JTA.
To work around it, I inject UserTransaction which I acquire by JNDI lookup. Is the following code thread-safe? Since both EntityManager and UserTransaction are instance variables but the methods are run by multiple threads.
How can I make it thread-safe but still be able to use Injection?
Thanks,
Yan
import com.google.inject.persist.Transactional;
import javax.persistence.EntityManager;
public class MyService {
@Inject EntityManager em;
@Inject UserTransaction // self-defined by JNDI look up
public void createNewPerson() {
em.persist(new Person(...));
}
public void createB() { em.persist(,,,)
}
}