6 Replies Latest reply on Oct 26, 2009 4:35 PM by Sascha Effert

    PersitenceUnit no more found after updating to SEAM 2.2

    Sascha Effert Newbie

      Hello,


      I have updated a project from SEAM 2.0.1 to 2.2. I also updated my JBoss Server from 4.2.2 to 5.1.0. After porting all my code to SEAM 2.2 I am not able to see some of my beans running. But I have one problem I do not know why it is going wrong:


      I generated a new seam project called mda2009. After starting, when I try to login using the web GUI I get an exception:


      21:26:19,286 WARN  [SeamLoginModule] Error invoking login method
      javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/mda2009/pu
           at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
      
      [....]
      
      Caused by: javax.naming.NameNotFoundException: mda2009 not bound
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
      
      [....]
      



      The whole output would be too much to copy it here, but it is here availabe.


      In the web.XML this defined as was done by seam-gen:


        <persistence-unit-ref>
            <persistence-unit-ref-name>mda2009/pu</persistence-unit-ref-name>
            <persistence-unit-name>../mda2009.jar#mda2009</persistence-unit-name>   
            <!-- The relative reference doesn't work on GlassFish. Instead, set the <persistence-unit-name> to "mda2009",
                 package persistence.xml in the WAR, and add a <jar-file> element in persistence.xml with value "../../mda2009.jar".
            <persistence-unit-name>mda2009</persistence-unit-name>
            -->
         </persistence-unit-ref>
      



      My persistence is defined as follows:


      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <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="mda2009">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>mda2009Datasource</jta-data-source>
            <!-- The <jar-file> element is necessary if you put the persistence.xml in the WAR and the classes in the JAR -->
            <!--
            <jar-file>../../vehicles.jar</jar-file>
            -->
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="validate"/>
               <property name="hibernate.show_sql" value="false"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.use_sql_comments" value="false"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/mda2009EntityManagerFactory"/>
            </properties>
         </persistence-unit>
          
      </persistence>
      



      My components.xml has an entry, I am not sure what it means:


         <persistence:managed-persistence-context name="entityManager" auto-create="true"
                            persistence-unit-jndi-name="@puJndiName@"/>
      



      I do not know, how to get rid of the error, so I can use my EntityManager (and log). Can please anybody help me?


      bests


      Sascha Effert

        • 1. Re: PersitenceUnit no more found after updating to SEAM 2.2
          Arbi Sookazian Master

          I never used the following with JBoss 4.2 in web.xml (it doesn't belong there).  Do you really need it or was this for Glassfish or other AS?


          In the web.XML this defined as was done by seam-gen:
          
            <persistence-unit-ref>
                <persistence-unit-ref-name>mda2009/pu</persistence-unit-ref-name>
                <persistence-unit-name>../mda2009.jar#mda2009</persistence-unit-name>   
                <!-- The relative reference doesn't work on GlassFish. Instead, set the <persistence-unit-name> to "mda2009",
                     package persistence.xml in the WAR, and add a <jar-file> element in persistence.xml with value "../../mda2009.jar".
                <persistence-unit-name>mda2009</persistence-unit-name>
                -->
             </persistence-unit-ref>


          • 2. Re: PersitenceUnit no more found after updating to SEAM 2.2
            Sascha Effert Newbie

            It was created by seam-gen. I also oved it out of the file, but then I get the same error during deployment.

            • 3. Re: PersitenceUnit no more found after updating to SEAM 2.2
              Sascha Effert Newbie

              sorry, oved means moved... Will have a closer look before saving next time...

              • 4. Re: PersitenceUnit no more found after updating to SEAM 2.2
                Sascha Effert Newbie

                I had a deeper look at what is happening, and I get even more confused. I have a StartupManager, which is used to do some work on startup, which works perfectly. Simplified, it can do following:


                import java.util.List;
                import org.jboss.seam.annotations.In;
                import org.jboss.seam.annotations.Logger;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.annotations.Observer;
                import org.jboss.seam.log.Log;
                import de.upb.vdrive.mda.model.security.User;
                
                @Name("bootstrapper")
                public class StartUpManager {
                
                  @In(create=true)
                  private UserManager userManager;
                
                  @Observer("org.jboss.seam.postInitialization")
                  public void initialisation() {
                    log.info("Users:");
                    for (User user : userManager.getUsers()) {
                      log.info("User #0", user.getName());
                    }
                  }
                }
                



                Using a UserManager doing the following it works:


                import java.util.List;
                import javax.ejb.Stateless;
                import javax.persistence.EntityManager;
                import de.upb.vdrive.mda.model.security.User;
                
                @Stateless
                @Name("userManager")
                public class UserManagerBean implements UserManager {
                  @In
                  private EntityManager entityManager;
                
                  public List<User> getUsers() {
                    return entityManager.createQuery("from User u").getResultList();
                  }
                



                Now, I want to work in a loginManager, I sepecified in components.xml as followed:


                 <security:identity authenticate-method="#{login.authenticate}" remember-me="true"/>
                



                In this loginBean I can not access any of my own message Beans. Following works:


                @Stateless
                @Name("login")
                public class LoginBean implements Login {
                
                  @PersistenceContext
                  private EntityManager entityManager;
                
                  @In
                  private Identity identity;
                     
                  @In
                  private Credentials credentials;
                
                  @Out(required = false)
                  private User user;
                     
                  @In
                  private transient FacesContext facesContext;
                
                  public boolean authenticate() {
                    List<User> resultList = entityManager.createQuery("from User u where name=:name").setParameter("name", credentials.getUsername()).getResultList();
                
                    if (resultList.size() == 0) {
                      log.warn("Login failed for user #0 (No User with that name)", credentials.getUsername());
                      return false;
                    } else {
                      log.info("Found user #0, checking password", credentials.getUsername());
                      user = resultList.get(0);
                      if (!user.getPassword().equals(credentials.getPassword())) {
                        log.warn("User #0 has wrong password #1 (should be #2)", credentials.getUsername(), credentials.getPassword(), user.getPassword());
                        user=null;
                        return false;
                      } else {
                        log.info("Password authentication fpr User #0 succeeded.", user.getName());
                      }
                      return true;
                    }
                  }
                }
                



                But if I want to use any SEAM Component it fails with the above mentioned Exception. e.g. if I realize my EntityManager using @In instead of using @PersistencyContext it fails at first usage of the EntityManager. Same happens if I try to access my UserManager as done in StartupManager. I do not understand why the UserManager is not bound in my LoginBean, but in the StartupManager.

                • 5. Re: PersitenceUnit no more found after updating to SEAM 2.2
                  Sascha Effert Newbie

                  I Managed to Login by using @PersistenceContext EntityManager and doing my initialisation stuff in mathof listening on the LoginSuccessfull Event. But after login in I have the same problem in everytime I try to reach Seam injected components inside mine xhtml file. So I can not access any of my SessionBeans from the Web GUI...

                  • 6. Re: PersitenceUnit no more found after updating to SEAM 2.2
                    Sascha Effert Newbie

                    I think I solved it with the help of this webside. I had to put the following to lines in my components.xml;


                     <persistence:entity-manager-factory name="mda2009Database" installed="false"/> 
                       
                       <persistence:managed-persistence-context name="entityManager" auto-create="true"
                           entity-manager-factory="#{mda2009Database}" persistence-unit-jndi-name="java:/mda2009EntityManagerFactory"/> 
                    



                    I do not know why seam-gen produces code, which does not work on JBoss 5...