Seam does not inject EntityManager?

I had problems with injecting an EntityManager instance in a Seam components. So I am listing here the things you need to check to get this working

1. Have the persistence.xml under the META-INF folder

2. Update the components.xml with the following entries. This configures the EntityManagerFactory.

<persistence:entity-manager-factory name=”POC” />
<persistence:managed-persistence-context name=”em” auto-create=”true” entity-manager-factory=”#{POC}”/>

3. entity-manager-factory’s name ‘POC’ is same as the persistence-unit name in persistence.xml

4.  EntityManager attribute name should be same as managed-persistence-context’s name. In this case, the code will look like
EntityManager em
This is the standard list that you will find anywhere. But remember that Seam injection will only work if the instantiation of a Seam component is under Seam’s direct control. If you have to create an instance of a class that is declared to be a Seam component then  you should not depend on Seam to inject the resources.


Find Singapore Apartment  and Room Rentals here

Looking for a date or love? Click here to find one for free!!

Stock Market Views, Experiences on

This entry was posted in Technology and tagged , . Bookmark the permalink.

2 Responses to Seam does not inject EntityManager?

  1. I follow your posts for a long time and should tell you that your posts always prove to be of a high value and quality for readers.

  2. Lucky Newbie says:

    Thank you very much!
    Finally I understood, how EntityManger Injection in Seam works. Had to use EJBs with @Stateful and @PersistenceContext and so every bean was a seam and ejb.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s