4 Replies Latest reply on Jan 29, 2007 6:16 PM by Adam Koprowski

    Problems with injection of persistence context.

    Adam Koprowski Newbie


      Hello,

      I'm running into problems with injection for persistence context. If in a session bean I do:

      @PersistenceContext private EntityManager em

      everything is fine, however if in the Seam component I do:
      @In(create=true) EntityManager em

      the application breaks up and I get:
      Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: newAuction.em
       at org.jboss.seam.Component.getInstanceToInject(Component.java:1882)
       at org.jboss.seam.Component.injectFields(Component.java:1348)
       at org.jboss.seam.Component.inject(Component.java:1118)
       at org.jboss.seam.interceptors.BijectionInterceptor.bijectNonreentrantComponent(BijectionInterceptor.java:76)
       at org.jboss.seam.interceptors.BijectionInterceptor.bijectComponent(BijectionInterceptor.java:58)
       ...
      


      Any ideas what may be wrong? I was thinking that maybe it's because I'm using Trinidad and according to the documentation I had to turn off the Seam view handler in web.xml (http://wiki.apache.org/myfaces/Facelets_with_Trinidad)
      <view-handler>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</view-handler>
      

      When I keep it indeed I get a Trinidad error:
      java.lang.IllegalStateException: No RenderingContext
       at org.apache.myfaces.trinidad.render.CoreRenderer.encodeBegin(CoreRenderer.java:159)
       at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeBegin(UIXComponentBase.java:667)
      

      Can it has something to do with that? Any help appreciated!

      Cheers,
      Adam Koprowski

        • 1. Re: Problems with injection of persistence context.
          Pete Muir Master

          Post your components.xml

          • 2. Re: Problems with injection of persistence context.
            Adam Koprowski Newbie

            Here it goes:

            components.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:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation=
             "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.1.xsd
             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.1.xsd">
            
             <core:init debug="true" jndi-pattern="@jndiPattern@"/>
            
             <core:manager concurrent-request-timeout="500"
             conversation-timeout="120000"
             conversation-id-parameter="cid"
             conversation-is-long-running-parameter="clr"/>
            
             <core:pages no-conversation-view-id="/home.xhtml"/>
            
             <core:managed-persistence-context name="entityManager"
             persistence-unit-jndi-name="java:/youdoEntityManagerFactory"/>
            
             <core:ejb installed="@embeddedEjb@"/>
            </components>
            


            persistence.xml:
            <?xml version="1.0" encoding="UTF-8"?>
            <persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
            
             <persistence-unit name="youdo">
             <provider>org.hibernate.ejb.HibernatePersistence</provider>
             <jta-data-source>java:/youdoDatasource</jta-data-source>
             <properties>
             <property name="hibernate.hbm2ddl.auto" value="update"/>
             <property name="hibernate.cache.use_query_cache" value="true"/>
             <property name="hibernate.show_sql" value="false"/>
             <property name="jboss.entity.manager.factory.jndi.name" value="java:/youdoEntityManagerFactory"/>
             </properties>
             </persistence-unit>
            
            </persistence>
            


            • 3. Re: Problems with injection of persistence context.
              Pete Muir Master

              There's your problem, you've called the component entityManager but are trying to inject it as em. Remember Seam injects by variable name NOT class/interface.

              • 4. Re: Problems with injection of persistence context.
                Adam Koprowski Newbie

                 

                Remember Seam injects by variable name NOT class/interface.


                Ups, I didn't know that. Sorry, I'm a newbie to Seam and the manual seems to go rather smoothly over such technicalities... Thanks a lot for help!
                Adam