3 Replies Latest reply on Mar 8, 2007 5:48 AM by giannidoe

    SeamEntityConverter - Cannot access entityManager

    giannidoe

      Just starting out with EJB3 and Seam ....
      I have followed the Wiki instructions for using s:selectItems with the SeamEntityConverter to populate a select menu, the menu is populated correctly but when I sumbit the form I get a Faces Message:
      "Cannot access entityManager; Either use the default name (entityManager) for your entity manager or specify it in components.xml"

      I do have the entity manager specified in components.xml:

      <components
      ......
      <core:managed-persistence-context
      name="entityManager"
      persistence-unit-jndi-name="java:/Orpello-PU"
      auto-create="true" />


      <h:selectOneMenu value="#{appUser.title}"
      id="usertitle" required="true" >
      <s:selectItems value="#{personTitles}"
      var="personTitle"
      label="#{personTitle.description}"
      noSelectionLabel="#{msgs['label.please-select']}"
      hideNoSelectionLabel="true" />
      <ec:convertEntity />
      </h:selectOneMenu>

      Seam version: 1.2.0.PATCH1

      Not sure where to go next and I'd appreciate it if someone could point me in the right direction.
      Thanks

        • 1. Re: SeamEntityConverter - Cannot access entityManager
          pmuir

          So an @In EntityManager entityManager works for you inside a Seam component?

          • 2. Re: SeamEntityConverter - Cannot access entityManager
            pmuir

            Yeah, so that error message is not very helpful :(

            Try putting a breakpoint on the loadEntityFromPersistenceContext in AbstractEntityConverter and track down what the actual exception thrown is.

            • 3. Re: SeamEntityConverter - Cannot access entityManager
              giannidoe

              Thanks, after trying to inject EntityManager with "@In EntityManager entityManager" I can see it's a problem with the JNDI binding.

              I'm running on Glassfish and I've tried the following:

              components.xml
              ---------------------
              <core:managed-persistence-context name="entityManager"
              persistence-unit-jndi-name="java:comp/env/persistence/Orpello-PU"
              auto-create="true" />

              in web.xml
              ---------------------
              <persistence-context-ref>
              <persistence-context-ref-name>persistence/Orpello-PU</persistence-context-ref-name>
              <persistence-unit-name>Orpello-PU</persistence-unit-name>
              </persistence-context-ref>

              persistence.xml
              ---------------------
              <persistence-unit name="Orpello-PU" transaction-type="JTA">


              .. and i get

              Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/persistence/Orpello-PU
              at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:751)
              at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:156)
              at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at org.jboss.seam.core.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:160)
              ... 115 more

              Maybe getting a bit off-topic here but can anyone help on how I should bind the entity manager into JNDI in Glassfish?
              From what I have read the <persistence-context-ref> in web.xml should do it.