1 Reply Latest reply on Jun 14, 2011 11:46 AM by esgoru

    EntityManager is null, i can´t injected

    esgoru Newbie

      i try using EntityManager, but i can´t instanced, i use tomcat v6.0 and mysql 4.1, i use hibernate and spring. my config archives is:

      jeveris-light-persistence.xml in web/scr/main/resources

      <?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="test" transaction-type="RESOURCE_LOCAL">
                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
      
      
                <jar-file>j-everis-ejb.jar</jar-file>
            <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 
                  <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> 
      
      
               <property name="hibernate.hbm2ddl.auto" value="update"/>
                <property name="hibernate.connection.username" value="root"/>
               <property name="hibernate.connection.password" value="jeveris"/>
               <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/bankeveris"/>
             </properties>
         </persistence-unit>
      </persistence>
      

      jeveris-ligth-persistence.xml in ejb/scr/main/resource/meta-inf

       

      <?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="test" transaction-type="RESOURCE_LOCAL">
                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 
                  <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> 
      
      
               <property name="hibernate.hbm2ddl.auto" value="update"/>
               <property name="hibernate.connection.username" value="root"/>
               <property name="hibernate.connection.password" value="jeveris"/>
               <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/bankeveris"/>
            </properties>
         </persistence-unit>
      </persistence>
      
      

      j-everis-mysql-ds.xml in app/jboss-ds

       

      <?xml version="1.0" encoding="UTF-8"?>
      
      
      
      
      <datasources>
         <local-tx-datasource>
            <!-- The jndi name of the DataSource, it is prefixed with java:/ -->
            <!-- Datasources are not available outside the virtual machine -->
            
                <jndi-name>jdbc/jeveris</jndi-name>
      
      
            <connection-url>jdbc:mysql://localhost:3306/bankeveris</connection-url>
      
      
            <!-- The driver class -->
            <driver-class>com.mysql.jdbc.Driver</driver-class>
      
      
            <!-- The login and password -->
            <user-name>root</user-name>
            <password>jeveris</password>
      
      
            <!--example of how to specify class that determines if exception means connection should be destroyed-->
            <!--exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.DummyExceptionSorter</exception-sorter-class-name-->
      
      
            <!-- this will be run before a managed connection is removed from the pool for use by a client-->
            <!--<check-valid-connection-sql>select * from something</check-valid-connection-sql> -->
      
      
            <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->
            <min-pool-size>5</min-pool-size>
      
      
            <!-- The maximum connections in a pool/sub-pool -->
            <max-pool-size>20</max-pool-size>
      
      
            <!-- The time before an unused connection is destroyed -->
            <!-- NOTE: This is the check period. It will be destroyed somewhere between 1x and 2x this timeout after last use -->
            <!-- TEMPORARY FIX! - Disable idle connection removal, HSQLDB has a problem with not reaping threads on closed connections -->
            <idle-timeout-minutes>0</idle-timeout-minutes>
      
      
            <!-- sql to call when connection is created
              <new-connection-sql>some arbitrary sql</new-connection-sql>
            -->
      
      
            <!-- sql to call on an existing pooled connection when it is obtained from pool 
               <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
            -->
      
      
            <!-- example of how to specify a class that determines a connection is valid before it is handed out from the pool
               <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.DummyValidConnectionChecker</valid-connection-checker-class-name>
            -->
      
      
            <!-- Whether to check all statements are closed when the connection is returned to the pool,
                 this is a debugging feature that should be turned off in production -->
            <track-statements/>
      
      
            <!-- Use the getConnection(user, pw) for logins
              <application-managed-security/>
             -->
      
      
            <!-- Use the security domain defined in conf/login-config.xml -->
            <!--  <security-domain>HsqlDbRealm</security-domain>-->
      
      
            <!-- Use the security domain defined in conf/login-config.xml or the
                 getConnection(user, pw) for logins. The security domain takes precedence.
              <security-domain-and-application>HsqlDbRealm</security-domain-and-application>
            -->
      
      
            <!-- HSQL DB benefits from prepared statement caching -->
            <prepared-statement-cache-size>32</prepared-statement-cache-size>
      
      
         </local-tx-datasource>
      </datasources>
      
      

       

      persistence.xml  in ejb/scr/main/resource/meta-inf

       

      <?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 ="j-everis-2.0">
                       <!-- jboss' default data source -->
                          <provider>org.hibernate.ejb.HibernatePersistence</provider>
      
      
      
                        <jta-data-source>java:/jdbc/jeveris</jta-data-source>
      
      
      
                     <properties>
      
                                              <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 
                                                <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />       
                                              <property name="hibernate.hbm2ddl.auto" value="update"/>
                                              <property name="hibernate.show_sql" value="true"/>
                                              <!-- Para evitar problemas con JBOSS -->
                                              <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
                          </properties> 
      
          </persistence-unit> 
      
      </persistence>
      
      
      

      clienteDaoImpl.java

       

      package com.bankeveris.dao;
      
      
      import java.util.List;
      
      
      import javax.ejb.Local;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.Persistence;
      
      
      import org.springframework.stereotype.Service; 
      
      
      import com.bankeveris.model.Cliente;
      
      
      @Stateless
      @Local(ClienteDao.class)
      @Service
      public class ClienteDaoImpl implements ClienteDao { 
      
                /** Entity Manager */
                @PersistenceContext 
                private EntityManager entityManager;  
      
      
                          @SuppressWarnings("unchecked")
                          public List<Cliente> findAllCliente() {
                                    System.out.println("Dao: Accediendo a BBDD....");
                                    return (List<Cliente>)entityManager.createNamedQuery("findAllCliente").getResultList();
                          }
      
      
                          public Cliente findCliente(int noCli) {
                                    Cliente cli= (Cliente)entityManager.createNamedQuery("findCliente").setParameter("nCli", noCli).getSingleResult();
                                    System.out.println("Cliente name: " + cli.getNombre());
                                    return cli;
                          }
      
      }
      
      

      when i do debugging, i have a one error, when i use entityManager in this line




      Cliente cli= (Cliente)entityManager.createNamedQuery("findCliente").setParameter("nCli", noCli).getSingleResult();

      it´s the error

       

      02882 [http-8080-1] WARN  com.jeveris.pl.navigation.executor.NavigationController  - Spring-defined bean not found for action service: com.bankeveris.flujo1DemoBankeveris.Service2F1. Instantiating brand-new action service...
      902913 [http-8080-1] INFO  com.jeveris.pl.navigation.model.ActionService  - Before executing ActionService: com.bankeveris.flujo1DemoBankeveris.Service2F1|flowInstanceId: 5317681774297516717|flowId: Flujo1DemoBankeveris|lastNodeId: BuscarCliente|requiredTransitionId: mandarDatos|nextNodeId: BuscarDatos|containerId: container_1
      902913 [http-8080-1] DEBUG com.jeveris.pl.context.beans.FlowScope  - view root: org.ajax4jsf.component.AjaxViewRoot@66bb78
      902913 [http-8080-1] DEBUG com.jeveris.pl.context.beans.FlowScope  - attributes: javax.faces.component.UIComponentBase$AttributesMap@b8a9dd16
      java.lang.NullPointerException
                at com.bankeveris.dao.ClienteDaoImpl.findCliente(ClienteDaoImpl.java:47)
                at com.bankeveris.service.ServiceClienteImpl.cliente(ServiceClienteImpl.java:29)
                at com.bankeveris.flujo1DemoBankeveris.Service2F1.execute(Service2F1.java:43)
                at com.jeveris.pl.navigation.model.ActionService.service(ActionService.java:41)
                at com.jeveris.pl.navigation.executor.NavigationController.processNavigation(NavigationController.java:149)
                at com.jeveris.pl.navigation.jsfintegration.PLNavigationHandler.handleNavigation(PLNavigationHandler.java:108)
                at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:130)
                at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:100)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
                at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                at java.lang.Thread.run(Thread.java:595)
      906366 [http-8080-1] ERROR com.jeveris.pl.navigation.executor.NavigationController  - Handle error for exception id=1308037940595: java.lang.NullPointerException
      906382 [http-8080-1] ERROR com.jeveris.pl.navigation.executor.NavigationController  - Flow information for exception id=1308037940595: flowInstanceId: 5317681774297516717|flowId: Flujo1DemoBankeveris|lastNodeId: BuscarCliente|requiredTransitionId: mandarDatos|nextNodeId: BuscarDatos|containerId: container_1
      906382 [http-8080-1] ERROR com.jeveris.pl.navigation.executor.NavigationController  - Go to error flow
      906382 [http-8080-1] INFO  com.jeveris.pl.navigation.executor.NavigationHelper  - Access to node errorService in flow error for resource com.jeveris.pl.core.services.ErrorService is granted
      906397 [http-8080-1] INFO  com.jeveris.pl.navigation.executor.NavigationHelper  - Flow started|flowInstanceId: 3810207644419029423|flowId: error|lastNodeId: null|requiredTransitionId: init|nextNodeId: errorService|containerId: container_1
      906444 [http-8080-1] DEBUG com.jeveris.pl.navigation.executor.NavigationController  - Searching for spring-defined bean errorService
      906444 [http-8080-1] WARN  com.jeveris.pl.businesslogic.control.BusinessLogicCaller  - Service (spring bean) with id errorService was not found. Returning null reference
      906460 [http-8080-1] WARN  com.jeveris.pl.navigation.executor.NavigationController  - Spring-defined bean not found for action service: com.jeveris.pl.core.services.ErrorService. Instantiating brand-new action service...
      906460 [http-8080-1] INFO  com.jeveris.pl.navigation.model.ActionService  - Before executing ActionService: com.jeveris.pl.core.services.ErrorService|flowInstanceId: 3810207644419029423|flowId: error|lastNodeId: null|requiredTransitionId: init|nextNodeId: errorService|containerId: container_1
      906476 [http-8080-1] INFO  MONITOR  - PLResource: com.jeveris.pl.core.services.ErrorService; Time: 0; Active Flow Info: flowInstanceId: 3810207644419029423|flowId: error|lastNodeId: null|requiredTransitionId: init|nextNodeId: errorService|containerId: container_1
      906491 [http-8080-1] INFO  com.jeveris.pl.navigation.model.ActionService  - Transition received: jeveris:end from ActionService: com.jeveris.pl.core.services.ErrorService|flowInstanceId: 3810207644419029423|flowId: error|lastNodeId: null|requiredTransitionId: init|nextNodeId: errorService|containerId: container_1
      
      

      I do conect hardcode with driverManager.getConection(), and It is good, i think this error is in configure archives.

      Please i need held.