users@glassfish.java.net

Re: entityManager does not persist if obtained through EntityManagerFactory

From: <glassfish_at_javadesktop.org>
Date: Wed, 22 Sep 2010 06:12:35 PDT

With the following code, which use BMT (Bean Managed Transaction), data are stored, but it would be better if transaction was managed by the container...

Is there a solution to use Container managed transaction?

@Stateless
public class FooManager {

        public String createFoo(int clientReference, int id, String fooName) {
                Foo foo = new Foo(id, fooName);
                EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("xa" + clientReference + "_datasource");
                EntityManager entityManager = entityManagerFactory.createEntityManager();
                EntityTransaction transaction = entityManager.getTransaction();
                transaction.begin();
                entityManager.persist(foo);
                transaction.commit();
                return fooName + " created";
        }
        
}
[Message sent by forum member 'i20']

http://forums.java.net/jive/thread.jspa?messageID=483329