Friday, February 8, 2013

gwt-guice JPA, inject EntityManager thread safe?

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(,,,)
        }

}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment