Seam Framework – Getting null entity manager

Hello everyone!

I’m trying to setup a jboss seam configuration with tomcat 6.0. Based on ‘jboss-seam-jpa’ example. And now almost everything working 🙂

I’ve solved a bunch of issues by searching in the forum, but this one I can’t solve.

When I’m try to inject entityManager on beans that extends classes of seam framework, such as EntityQuery or EntityHome, I’m getting this error:

org.jboss.seam.InstantiationException: Could not instantiate Seam component: carteiraHome
	at org.jboss.seam.Component.newInstance(Component.java:2106)
	at org.jboss.seam.Component.getInstance(Component.java:1988)
...
Caused by: java.lang.IllegalStateException: entityManager is null
	at org.jboss.seam.framework.EntityHome.create(EntityHome.java:33)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
...

Here’s my component.xml

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
            xmlns:core="http://jboss.com/products/seam/core"
            xmlns:persistence="http://jboss.com/products/seam/persistence"
            xmlns:transaction="http://jboss.com/products/seam/transaction"
            xmlns:security="http://jboss.com/products/seam/security"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:ui="http://jboss.com/products/seam/ui"
            xsi:schemaLocation=
                "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd 
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">

    <core:manager conversation-timeout="120000" 
                  concurrent-request-timeout="500"
                  conversation-id-parameter="cid"/>

    <transaction:entity-transaction 
    	entity-manager="#{em}"/>

    <persistence:entity-manager-factory name="bookingDatabase"/>

    <persistence:managed-persistence-context
    				name="em"
                    auto-create="true" 
                    entity-manager-factory="#{bookingDatabase}"
                    persistence-unit-jndi-name="java:/jpaBookingEntityManagerFactory"/>

    <security:identity authenticate-method="#{authenticator.authenticate}"/>  

</components>

thanks in advance! 🙂

Solution:

Try this configuration:

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