2 Replies Latest reply on Jun 19, 2011 3:27 AM by Obinna Henry

    Help Newbie With org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory

    Obinna Henry Newbie
      hi, i am new to jboss seam, and i am using 2.2.2 with jsf1.2. i have set up my project in netbeans and i am trying to use JPA. but when i try to deploy the application i get the following exception: Please dont mind the formatting, couldnt get it to work.

      '
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
              at org.jboss.seam.Component.newInstance(Component.java:2170)

      '

      Here is my components.xml file
      '
      <b>
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:web="http://jboss.com/products/seam/web"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd">


          <core:init jndi-pattern="SeamFacelets/#{ejbName}/local"/>

          <core:manager conversation-timeout="120000"
                        concurrent-request-timeout="500"
                        conversation-id-parameter="cid"/>
        
          <persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="SeamFacelets-ejbPU"/>
          <persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" />

          <security:identity authenticate-method="#{authenticator.authenticate}"/>
           
      </components>
      </b>
      '

      Here is my persistence.xml file

      '
      <?xml version="1.0" encoding="UTF-8"?>
      <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="SeamFacelets-ejbPU" transaction-type="JTA">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>java:/ObiMySqlDS</jta-data-source>
          <exclude-unlisted-classes>false</exclude-unlisted-classes>
          <properties>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                       <!-- Binds the EntityManagerFactory to JNDI where Seam can look it up.
                    This is only relevant when the container automatically loads the persistence unit, as is the case in JBoss AS 5. -->
             <!--  <property name="jboss.entity.manager.factory.jndi.name" value="java:/seamFaceletsEntityManagerFactory"/>-->
            </properties>
        </persistence-unit>
      </persistence>

      '

      Here is my jboss-ds.xml file:

      '
      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
        <local-tx-datasource>
          <jndi-name>ObiMySqlDS</jndi-name>
          <connection-url>jdbc:mysql://localhost:3306/hr</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>root</user-name>
          <password>opt1mus#</password>
          <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
            <metadata>
             <type-mapping>mySQL</type-mapping>
          </metadata>
        </local-tx-datasource>
      </datasources>


      '

      I really need to move on. I have been stuck for some time trying to figure this out.
      If you have tutorial links to help me, i would appreciate it a lot.
        • 1. Re: Help Newbie With org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
          Obinna Henry Newbie
          ok, after some research and modifications, i didnt get the above exception anymore, the aplication deploys but when i try to access a page shown bellow i get the following exception:

          "23:24:35,576 SEVERE [viewhandler] Error Rendering View[/employees.xhtml]
          javax.ejb.EJBTransactionRolledbackException
                  at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
          "

          Here is the employees.xhtml page:
          -----------------------------
          ...
          <f:view>
                   <h:form>
                         <h:dataTable value="#{employees}" var="emp" >
                          <h:column>
                              <f:facet name="header" >Employee ID</f:facet>
                              <h:outputText>
                                  #{emp.employeeId}
                              </h:outputText>
                          </h:column>
                      </h:dataTable>
                   </h:form>
          </f:view>
          ...

          Here is the stateless session bean
          -----------------------------------
          @Stateless
          @Name("employeeManager")
          public class EmployeesBeanBean implements EmployeesBeanLocal {

              @PersistenceContext(unitName = "SeamFacelets-ejbPU")
              EntityManager em;

              @SuppressWarnings("unused")   
              @DataModel
              List<Employees> employees;

              @SuppressWarnings("unchecked")
              @Factory("employees")
              public void findEmployees() {
                  System.out.println("finding employees....");
                  employees = em.createQuery("select e from Employees e").getResultList();
              }


          }

          Here is the components.xml file now
          ------------------------------------
          <?xml version="1.0" encoding="UTF-8"?>
          <components xmlns="http://jboss.com/products/seam/components"
                      xmlns:core="http://jboss.com/products/seam/core"
                      xmlns:persistence="http://jboss.com/products/seam/persistence"
                      xmlns:drools="http://jboss.com/products/seam/drools"
                      xmlns:bpm="http://jboss.com/products/seam/bpm"
                      xmlns:security="http://jboss.com/products/seam/security"
                      xmlns:mail="http://jboss.com/products/seam/mail"
                      xmlns:web="http://jboss.com/products/seam/web"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation=
                          "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                           http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                           http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
                           http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
                           http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                           http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
                           http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                           http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd">


              <core:init jndi-pattern="SeamFacelets/#{ejbName}/local"/>
                  
          </components>

          Here is the persistence.xml file too
          ----------------------------------------

          <?xml version="1.0" encoding="UTF-8"?>
          <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="SeamFacelets-ejbPU" transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:/ObiMySqlDS</jta-data-source>
              <exclude-unlisted-classes>false</exclude-unlisted-classes>
              <properties>
                   <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                   <property name="hibernate.show_sql" value="true"/>
                   <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                   <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                           <!-- Binds the EntityManagerFactory to JNDI where Seam can look it up.
                        This is only relevant when the container automatically loads the persistence unit, as is the case in JBoss AS 5. -->
                 <!--  <property name="jboss.entity.manager.factory.jndi.name" value="java:/seamFaceletsEntityManagerFactory"/>-->
                </properties>
            </persistence-unit>
          </persistence>
          ..........

          What could be the problem?
          • 2. Re: Help Newbie With org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
            Obinna Henry Newbie

            yaayy!!!, i got it working.
            i studied the registration sample that ships with seam and configured my project exactly and it deployed and everything is working fine.