4 Replies Latest reply on Jun 15, 2007 4:43 PM by Steven Gollery

    Problems setting up Seam-managed persistence context

    Steven Gollery Newbie

      I have a small Seam (1.2.1) application running in Tomcat 5.5.23 and using Hibernate and the Embedded EJB3 container. It works so far when I inject the EntityManager like this:

      @PersistenceContext
      private EntityManager em;

      Now I'm trying to use a Seam-managed persistence context instead. Following instructions at http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/persistence.html and many other places, I added this to context.xml:

      <core:managed-persistence-context name="myDatabase"
      auto-create="true"
      persistence-unit-jndi-name="java:/EntityManagerFactories/myData"/>

      And in persistence.xml, added this to the properties list:

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

      In one of my session beans, I added:

      @In private EntityManager myDatabase;

      But as soon as a method in that session bean is executed, I get this exception:

      org.jboss.seam.RequiredException: In attribute requires non-null value: myBean.myDatabase

      This happens even if I use:

      @In(create = true)

      I've also tried to use a Seam-managed Hibernate session, but I can't get that to work either.

      Apparently I'm missing something. Any idea what it is?

      Steve Gollery

        • 1. Re: Problems setting up Seam-managed persistence context
          Fernando Montaño Expert

          Have you configured your <jta-data-source/> name of your persistence.xml in the jboss-beans.xml?

          • 2. Re: Problems setting up Seam-managed persistence context
            Steven Gollery Newbie

            Fernando,

            In persistence.xml, I have

            <jta-data-source>java:/myDatasource</jta-data-source>

            In jboss-beans.xml, I have

             <bean name="myDatasourceBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
             <property name="driverClass">com.mysql.jdbc.Driver</property>
             ....other properties....
             <property name="transactionManager"><inject bean="TransactionManager"/></property>
             <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
             <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
             </bean>
            
             <bean name="myDatasource" class="java.lang.Object">
             <constructor factoryMethod="getDatasource">
             <factory bean="myDatasourceBootstrap"/>
             </constructor>
             </bean>
            


            Is that what you mean? Does it look right? The whole thing works if I use @PersistenceContext, so it seems like the setup must be reasonably correct.

            Steve


            • 3. Re: Problems setting up Seam-managed persistence context
              Fernando Montaño Expert

              Yes, it was I meant. You are right if @PersistenceContext is working fine, it seems the problem is with some configuration (components.xml) or component declaration.

              Could I see your components.xml configuration and also the whole class (component) where you are trying to inject the the EntityManager in.

              • 4. Re: Problems setting up Seam-managed persistence context
                Steven Gollery Newbie

                Fernando,

                In trying to put together a stripped-down class for you, I found out what was wrong.

                In the class where I was trying to inject the seam-managed persistence context, I also had several UIInput objects that were bound to components in the xhtml. Without the UIInput objects, everything works fine, but with them I get the exception I listed above.

                I'm not sure why having the bound UIInput objects would cause the seam-managed persistence context injection to fail, but it may be something to do with the JSF lifecycle -- maybe the point where bound objects are set into the backing beans is too early for the persistence context, or something.

                Anyway, it looks like I've got this fixed now. Thanks for looking at it.

                Steve