On Mar 20, 2009, at 9:46 AM, Olivier THIERRY wrote:

2009/3/19 David Blevins <[email protected]>:

On Mar 18, 2009, at 8:40 AM, Olivier THIERRY wrote:

Hi,

I try to configure a Seam-managed persistence context with Open EJB 3.0. To achieve this, I need to get entity manager factory using its JNDI name.

For example, for JBoss, it is something like this :

<property name="jboss.entity.manager.factory.jndi.name"
value="java:/EntityManagerFactories/bookingData"/>

But I can't find the equivalent for Open EJB. So what is the JNDI name
for OpenEJB entity manager factory ?

In the current releases there's no global JNDI name for EntityManagerFactory instances. In the trunk version (3.1.1) there is work on that might help.

In the meantime, do you know if Seam can lookup from an EJB's or Servlet's java:comp namespace? If that works, you could add an @PersistenceUnit ref
(or equivalent xml) somewhere.

-David



Thanks David,

One more time you were right ! I found a way to make it work and it
uses @PersistenceUnit as you suggested.

I created the following Seam component that is used as entity manager factory :

@Stateless
@Name("entityManagerFactory")
public class EntityManagerFactoryHackBean implements
EntityManagerFactoryHackLocal {
        
        @PersistenceUnit(name="t4Seam")
        EntityManagerFactory entityManagerFactory;
        
        @Unwrap
        public EntityManagerFactory getEntityMangagerFactory()
        {
                return entityManagerFactory;
        }

}

And I configured Seam this way in components.xml :

   <persistence:managed-persistence-context
        name="emanager"
                auto-create="true"
                entity-manager-factory="#{entityManagerFactory}" />

This way Seam creates a "emanager" Seam component with EntityManager
type and put it in conversation scope, so that it can be retrieved the
following way in all Seam components running in the conversation :

   @org.jboss.seam.annotations.In
   protected javax.persistence.EntityManager emanager;

So it looks OK with Seam managed persistence context now.

But now I have some problems with Seam managed transactions. Anyway I
am note sure yet if it's a problem with OpenEJB or Seam.

Have a nice week-end

That's a great technique and similar to the one people use for Spring.

Hopefully Seam will allow you to supply a UserTransaction via the same technique. Something like this might work:

    @Stateless
    @TransactionManagement(TransactionManagementType.BEAN)
    @Name("userTransaction")
    public class UserTransactionHackBean implements
    UserTransactionHackLocal {
        
        @Resource
        UserTransaction userTransaction;
        
        @Unwrap
        public UserTransaction getUserTransaction()
        {
            return userTransaction;
        }
    }

I don't know Seam to any real degree, but ideally you could combine the two like so:

    @Stateless
    @TransactionManagement(TransactionManagementType.BEAN)
    @Name("resourcesBean")
    public class ResourcesBean implements ResourcesLocal {

        @Resource
        UserTransaction userTransaction;

        @PersistenceUnit(name = "t4Seam")
        EntityManagerFactory entityManagerFactory;

        @Unwrap
        public EntityManagerFactory getEntityMangagerFactory() {
            return entityManagerFactory;
        }

        @Unwrap
        public UserTransaction getUserTransaction() {
            return userTransaction;
        }
    }

Let me know if you try it. Good info for the archives and we can start throwing this into a doc.

-David


Reply via email to