1 Reply Latest reply on Jun 30, 2009 9:20 PM by pedalshoe

    Null entity manager


      I feel like I'm going backwards here because I'm really trying to solve a different problem.  The entityManager is always null at the point I need it.  I'm creating a seam application in an ear file.
      seam 2.1.2, jbossAS 4.2.3 is my environment.
      Any help is greatly appreciated.

      1. components.xml contains:

              name="entityManager" auto-create="true"
      <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>

      2. persistence.xml contains:

      <persistence version="1.0" 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">
        <persistence-unit name="myDB" transaction-type="JTA">
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.use_sql_comments" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/myDBEntityManagerFactory"/>

      3: After I authenticate using the authenticate-method specified in components.xml I load a xhtml page that has a bean that injects the entityManager:

      public class ExtendedTableBean implements Serializable {
          EntityManager entityManager;
          private List<Language> languages; // the data
          public void getLanguages() {
              if (entityManager == null) {
                  System.err.println("ExtendedTableBean.getLanguages() entityManager is null");
              } else {
                  Query q = entityManager.createQuery("select L from Language");
                  languages = q.getResultList();
                  System.out.println("Languages len=" + languages.size() + " languages=" + languages.toArray());
          private Language selectedLanguage; // the user selected language

      4. at the time this bean is needed for the page the entityManager is always null at the @In annotation before I actually use the entityManager. The entityManager is set for auto-create true in components.xml but I still get the following exception:

      14:05:22,140 ERROR [STDERR] Jun 30, 2009 2:05:22 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/acct/index.xhtml]
      org.jboss.seam.RequiredException: @In attribute requires non-null value: extendedTableBean.entityManager
              at org.jboss.seam.Component.getValueToInject(Component.java:2335)
              at org.jboss.seam.Component.injectAttributes(Component.java:1736)
              at org.jboss.seam.Component.inject(Component.java:1554)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)

      Any help is greatly appreciated.
      Thank you,

        • 1. Re: Null entity manager

          I must be getting tired or deadline but, my entityManger isn't null anymore and is working as I expected.  But I'm not sure (yet) how I got it to work or what happened to me locally but it is working as I documented it above... (I'm so beat up right now).