7 Replies Latest reply on Jun 19, 2008 2:57 AM by Ramazan Pekin

    EntityManager Injection, Null Pointer Exception. (Sorry...)

    Ramazan Pekin Newbie

      I wanted the entitymanager have been injected by the container. But after a lot of trial, I decided to ask the question.

      Here is the situation,

      JBoss Server:jboss-4.2.2.GA


      My ear file structure:

      surgeonfish.ear
      |----surgeonfish-ds.xml
      |----META-INF
       |----application.xml
       |----jboss-app.xml
       |----MANIFEST.MF
      |----surgeonfish.jar
       |----com.beans...
       |----META-INF
       |----persistence.xml
       |----MANIFEST.MF
      |----surgeonfish.war
       |----META-INF
       |----MANIFEST.MF
       |----WEB-INF
       |----classes
       |----lib
       |----web.xml
      

      ----------------
      HERE ARE MY CONFIG FILES:
      ----------------
      surgeonfish-ds.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
       <local-tx-datasource>
       <jndi-name>time_reporting_data_source</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/timereporting</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>root</user-name>
       <password>test</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>
      

      ----------------
      application.xml
      <application>
       <display-name>Surgeonfish</display-name>
       <module>
       <web>
       <web-uri>surgeonfish.war</web-uri>
       <context-root>/surgeonfish</context-root>
       </web>
       </module>
       <module>
       <ejb>surgeonfish.jar</ejb>
       </module>
      </application>
      

      ---------------
      jboss-app.xml:
      <jboss-app>
       <module>
       <service>surgeonfish-ds.xml</service>
       </module>
       <loader-repository>
       surgeonfish:archive=surgeonfish.ear
       </loader-repository>
      </jboss-app>
      

      --------------
      persistence.xml:
      <persistence>
       <persistence-unit name="time_report_persistence_context">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/time_reporting_data_source</jta-data-source>
       <jar-file>../surgeonfish.jar</jar-file>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
       <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
       </properties>
       </persistence-unit>
      </persistence>
      

      ----------------------
      Here my test bean:
      package com.xyz...;
      
      
      import javax.ejb.Local;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceContext;
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      
      @Stateless
      @Local(value=PrStaffInterface.class)
      public class PrStaffHome {
      
       private static final Log log = LogFactory.getLog(PrStaffHome.class);
      
       @PersistenceContext(unitName="time_report_persistence_context")
       private EntityManager entityManager;
      
       public PrStaff findById(Integer id) {
       log.debug("getting PrStaff instance with id: " + id);
       try {
       /*
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("time_report_persistence_context");
       EntityManager em = emf.createEntityManager();
       PrStaff instance1 = em.find(PrStaff.class, id);
       ---this lines working without any error...---
       */
      
       PrStaff instance = entityManager.find(PrStaff.class, id);->I am taking null pointer exception here...
       System.out.println("instance:"+instance);
       log.debug("get successful");
       return instance;
       } catch (RuntimeException re) {
       log.error("get failed", re);
       throw re;
       }
       }
      }
      


      I cant find reason, why container is not injecting the entity manager. Of course I am missing something but I cant find. Thanks for your helps...

        • 1. Re: EntityManager Injection, Null Pointer Exception. (Sorry.
          jaikiran pai Master

          Please post the entire exception stacktrace. Also post the logs from the console which you see when the application is being deployed. Which version of Java do you use?

          • 2. Re: EntityManager Injection, Null Pointer Exception. (Sorry.
            Ramazan Pekin Newbie

            Hi,

            First of all java-version info:
            C:\>java -version
            java version "1.5.0_11"
            Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
            Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)



            Here are the full console outline when I start jboss:
            ------------------------------------------------------------------------------
            ===============================================================================

            JBoss Bootstrap Environment

            JBOSS_HOME: C:\jboss

            JAVA: C:\Program Files\Java\jdk1.5.0_11\bin\java

            JAVA_OPTS: -Dprogram.name=run.bat -server -Xms128m -Xmx512m -Dsun.rmi.dgc.cli
            ent.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000

            CLASSPATH: C:\Program Files\Java\jdk1.5.0_11\lib\tools.jar;C:\jboss\bin\run.jar

            ===============================================================================

            17:45:49,974 INFO [Server] Starting JBoss (MX MicroKernel)...
            17:45:49,974 INFO [Server] Release ID: JBoss [Trinity] 4.2.2.GA (build: SVNTag=
            JBoss_4_2_2_GA date=200710221139)
            17:45:49,974 INFO [Server] Home Dir: C:\jboss
            17:45:49,974 INFO [Server] Home URL: file:/C:/jboss/
            17:45:49,974 INFO [Server] Patch URL: null
            17:45:49,974 INFO [Server] Server Name: default
            17:45:49,974 INFO [Server] Server Home Dir: C:\jboss\server\default
            17:45:49,974 INFO [Server] Server Home URL: file:/C:/jboss/server/default/
            17:45:49,974 INFO [Server] Server Log Dir: C:\jboss\server\default\log
            17:45:49,974 INFO [Server] Server Temp Dir: C:\jboss\server\default\tmp
            17:45:49,974 INFO [Server] Root Deployment Filename: jboss-service.xml
            17:45:50,318 INFO [ServerInfo] Java version: 1.5.0_11,Sun Microsystems Inc.
            17:45:50,318 INFO [ServerInfo] Java VM: Java HotSpot(TM) Server VM 1.5.0_11-b03
            ,Sun Microsystems Inc.
            17:45:50,318 INFO [ServerInfo] OS-System: Windows XP 5.1,x86
            17:45:50,912 INFO [Server] Core system initialized
            17:45:53,974 INFO [WebService] Using RMI server codebase: http://127.0.0.1:8083
            /
            17:45:53,990 INFO [Log4jService$URLWatchTimerTask] Configuring from URL: resource:jboss-log4j.xml
            17:45:55,006 INFO [TransactionManagerService] JBossTS Transaction Service (JTAversion) - JBoss Inc.
            17:45:55,006 INFO [TransactionManagerService] Setting up property manager MBean and JMX layer
            17:45:55,287 INFO [TransactionManagerService] Starting recovery manager
            17:45:55,474 INFO [TransactionManagerService] Recovery manager started
            17:45:55,474 INFO [TransactionManagerService] Binding TransactionManager JNDI Reference
            17:45:59,709 INFO [EJB3Deployer] Starting java:comp multiplexer
            17:46:00,209 INFO [STDOUT] no object for null
            17:46:00,209 INFO [STDOUT] no object for null
            17:46:00,240 INFO [STDOUT] no object for null
            17:46:00,272 INFO [STDOUT] no object for {urn:jboss:bean-deployer}supplyType
            17:46:00,287 INFO [STDOUT] no object for {urn:jboss:bean-deployer}dependsType
            17:46:03,037 INFO [NativeServerConfig] JBoss Web Services - Native
            17:46:03,037 INFO [NativeServerConfig] jbossws-native-2.0.1.SP2 (build=200710210837)
            17:46:04,647 INFO [Embedded] Catalina naming disabled
            17:46:04,959 INFO [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the j
            .library.path: C:\Program Files\Java\jdk1.5.0_11\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\oraclexe\app\oracle\product\10.2.0\server\bin;D:\oracle\product\10.2
            db_1\bin;D:\oracle\product\10.2.0\client_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\HPQ\IAM\bin;C:\Program Files\Java\jdk
            .0_11\bin;D:\derby\bin;D:\cygwin\bin;D:\JSF\eclipse\plugins\org.apache.ant_1.6.5\bin;;D:\Perl\bin;D:\maven-2.0.7\bin;C:\Program Files\SecureCRT 3.0;C:\java\a
            bin;;C:\Program Files\Smart Projects\IsoBuster;C:\Sun\SDK\bin;C:\java\cvsnt\
            17:46:05,178 INFO [Http11Protocol] Initializing Coyote HTTP/1.1 on http-127.0.0.1-8080
            17:46:05,178 INFO [AjpProtocol] Initializing Coyote AJP/1.3 on ajp-127.0.0.1-8009
            17:46:05,194 INFO [Catalina] Initialization processed in 546 ms
            17:46:05,194 INFO [StandardService] Starting service jboss.web
            17:46:05,194 INFO [StandardEngine] Starting Servlet Engine: JBossWeb/2.0.1.GA
            17:46:05,256 INFO [Catalina] Server startup in 63 ms
            17:46:05,366 INFO [TomcatDeployer] deploy, ctxPath=/, warUrl=.../deploy/jboss-web.deployer/ROOT.war/
            17:46:06,194 INFO [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=.../deploy/http-invoker.sar/invoker.war/
            17:46:06,553 INFO [TomcatDeployer] deploy, ctxPath=/jbossws, warUrl=.../deploy/jbossws.sar/jbossws-context.war/
            17:46:06,741 INFO [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=.../deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/
            17:46:08,803 INFO [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=.../deploy/management/console-mgr.sar/web-console.war/
            17:46:09,506 INFO [MailService] Mail Service bound to java:/Mail
            17:46:09,772 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-local-jdbc.rar
            17:46:09,881 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-xa-jdbc.rar
            17:46:09,991 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-local-jdbc.rar
            17:46:10,038 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-xa-jdbc.rar
            17:46:10,116 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jms/jms-ra.rar
            17:46:10,459 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/mail-ra.rar
            17:46:10,522 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/quartz-ra.rar
            17:46:10,522 INFO [QuartzResourceAdapter] start quartz!!!
            17:46:10,600 INFO [SimpleThreadPool] Job execution threads will use class loader of thread: main
            17:46:10,631 INFO [QuartzScheduler] Quartz Scheduler v.1.5.2 created.
            17:46:10,647 INFO [RAMJobStore] RAMJobStore initialized.
            17:46:10,647 INFO [StdSchedulerFactory] Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properti

            17:46:10,647 INFO [StdSchedulerFactory] Quartz scheduler version: 1.5.2
            17:46:10,647 INFO [QuartzScheduler] Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
            17:46:11,366 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultD
            17:46:11,803 INFO [A] Bound to JNDI name: queue/A
            17:46:11,803 INFO [B] Bound to JNDI name: queue/B
            17:46:11,819 INFO [C] Bound to JNDI name: queue/C
            17:46:11,819 INFO [D] Bound to JNDI name: queue/D
            17:46:11,819 INFO [ex] Bound to JNDI name: queue/ex
            17:46:11,850 INFO [testTopic] Bound to JNDI name: topic/testTopic
            17:46:11,850 INFO [securedTopic] Bound to JNDI name: topic/securedTopic
            17:46:11,850 INFO [testDurableTopic] Bound to JNDI name: topic/testDurableTopic
            17:46:11,850 INFO [testQueue] Bound to JNDI name: queue/testQueue
            17:46:11,913 INFO [UILServerILService] JBossMQ UIL service available at : /127.0.0.1:8093
            17:46:11,944 INFO [DLQ] Bound to JNDI name: queue/DLQ
            17:46:12,085 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA
            17:46:12,131 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
            17:46:12,444 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
            17:46:12,460 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
            17:46:12,475 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 22s:485ms
            ------------------------------------------------------------------------------


            HERE ARE THE CONSOLE OUTLINE WHEN I DEPLOY THE APPLICATION:
            ------------------------------------------------------------------------------
            17:50:38,032 INFO [EARDeployer] Init J2EE application: file:/C:/jboss/server/default/deploy/surgeonfish.ear
            17:50:39,548 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=time_reporting_data_source' to JNDI na
            'java:time_reporting_data_source'
            17:50:39,548 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.entity.PersistenceUnitDeployment
            17:50:39,564 INFO [JmxKernelAbstraction] installing MBean: persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_contex
            ith dependencies:
            17:50:39,564 INFO [JmxKernelAbstraction] jboss.jca:name=time_reporting_data_source,service=DataSourceBinding
            17:50:39,564 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persi
            nce_context
            17:50:39,610 INFO [Version] Hibernate Annotations 3.3.1.GA
            17:50:39,626 ERROR [STDERR] 172 [ScannerThread] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.CR1
            17:50:39,642 ERROR [STDERR] 188 [ScannerThread] INFO org.hibernate.cfg.Environment - hibernate.properties not found
            17:50:39,642 ERROR [STDERR] 188 [ScannerThread] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
            17:50:39,657 ERROR [STDERR] 203 [ScannerThread] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
            17:50:39,767 INFO [Version] Hibernate EntityManager 3.3.2.GA
            17:50:39,970 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrGroups
            17:50:40,048 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrGroups on table pr_groups
            17:50:40,110 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrStaff
            17:50:40,110 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrStaff on table pr_staff
            17:50:40,142 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
            17:50:40,282 ERROR [STDERR] 828 [ScannerThread] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.hibernate.ejb
            nnection.InjectedDataSourceConnectionProvider
            17:50:40,298 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
            17:50:40,595 ERROR [STDERR] 1141 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.1.12-beta-community-nt
            17:50:40,610 ERROR [STDERR] 1156 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.
            ( Revision: ${svn.Revision} )
            17:50:40,626 ERROR [STDERR] 1172 [ScannerThread] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
            17:50:40,642 ERROR [STDERR] 1188 [ScannerThread] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.ejb.transacti
            JoinableCMTTransactionFactory
            17:50:40,642 ERROR [STDERR] 1188 [ScannerThread] INFO org.hibernate.transaction.TransactionManagerLookupFactory - instantiating TransactionManagerLookup: org
            bernate.transaction.JBossTransactionManagerLookup
            17:50:40,657 ERROR [STDERR] 1203 [ScannerThread] INFO org.hibernate.transaction.TransactionManagerLookupFactory - instantiated TransactionManagerLookup
            17:50:40,657 ERROR [STDERR] 1203 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
            17:50:40,657 ERROR [STDERR] 1203 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
            17:50:40,657 ERROR [STDERR] 1203 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
            17:50:40,657 ERROR [STDERR] 1203 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
            17:50:40,673 ERROR [STDERR] 1219 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
            17:50:40,673 ERROR [STDERR] 1219 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
            17:50:40,673 ERROR [STDERR] 1219 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
            17:50:40,673 ERROR [STDERR] 1219 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
            17:50:40,673 ERROR [STDERR] 1219 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
            17:50:40,673 ERROR [STDERR] 1219 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
            17:50:40,689 ERROR [STDERR] 1235 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
            17:50:40,689 ERROR [STDERR] 1235 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
            17:50:40,689 ERROR [STDERR] 1235 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
            17:50:40,689 ERROR [STDERR] 1235 [ScannerThread] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
            17:50:40,689 ERROR [STDERR] 1235 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
            17:50:40,704 ERROR [STDERR] 1250 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: enabled
            17:50:40,704 ERROR [STDERR] 1250 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
            17:50:40,704 ERROR [STDERR] 1250 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
            17:50:40,704 ERROR [STDERR] 1250 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactor
            cheProviderBridge
            17:50:40,720 ERROR [STDERR] 1266 [ScannerThread] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.
            htableCacheProvider
            17:50:40,720 ERROR [STDERR] 1266 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
            17:50:40,720 ERROR [STDERR] 1266 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Cache region prefix: surgeonfish_ear,surgeonfish_jar,time_report_pe
            stence_context
            17:50:40,735 ERROR [STDERR] 1281 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
            17:50:40,735 ERROR [STDERR] 1281 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
            17:50:40,735 ERROR [STDERR] 1281 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
            17:50:40,751 ERROR [STDERR] 1297 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
            17:50:40,751 ERROR [STDERR] 1297 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
            17:50:40,751 ERROR [STDERR] 1297 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
            17:50:40,814 ERROR [STDERR] 1360 [ScannerThread] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
            17:50:41,126 ERROR [STDERR] 1672 [ScannerThread] INFO org.hibernate.impl.SessionFactoryObjectFactory - Factory name: persistence.units:ear=surgeonfish.ear,ja
            urgeonfish.jar,unitName=time_report_persistence_context
            17:50:41,142 ERROR [STDERR] 1688 [ScannerThread] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.i
            rfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
            17:50:41,142 ERROR [STDERR] 1688 [ScannerThread] INFO org.hibernate.impl.SessionFactoryObjectFactory - Bound factory to JNDI name: persistence.units:ear=surg
            fish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
            17:50:41,142 ERROR [STDERR] 1688 [ScannerThread] WARN org.hibernate.impl.SessionFactoryObjectFactory - InitialContext did not implement EventContext
            17:50:41,157 ERROR [STDERR] 1703 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
            17:50:41,173 ERROR [STDERR] 1719 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
            17:50:41,204 ERROR [STDERR] 1750 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
            17:50:41,204 ERROR [STDERR] 1750 [ScannerThread] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.i
            rfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
            17:50:41,267 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
            17:50:41,282 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=surgeonfish.ear,jar=surgeonfish.jar,name=PrGroupsHome,service=EJB3 with dependenci

            17:50:41,282 INFO [JmxKernelAbstraction] persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
            17:50:41,470 INFO [EJBContainer] STARTED EJB: com.atosorigin.utils.pojo.PrGroupsHome ejbName: PrGroupsHome
            17:50:41,517 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
            17:50:41,517 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=surgeonfish.ear,jar=surgeonfish.jar,name=PrStaffHome,service=EJB3 with dependencie
            17:50:41,517 INFO [JmxKernelAbstraction] persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
            17:50:41,532 INFO [EJBContainer] STARTED EJB: com.atosorigin.utils.pojo.PrStaffHome ejbName: PrStaffHome
            17:50:41,689 INFO [EJB3Deployer] Deployed: file:/C:/jboss/server/default/tmp/deploy/tmp12828surgeonfish.ear-contents/surgeonfish.jar
            17:50:41,704 INFO [TomcatDeployer] deploy, ctxPath=/surgeonfish, warUrl=.../tmp/deploy/tmp12828surgeonfish.ear-contents/surgeonfish-exp.war/
            17:50:41,939 INFO [EARDeployer] Started J2EE application: file:/C:/jboss/server/default/deploy/surgeonfish.ear






            WHEN I TRY IT I AM TAKING ERROR:
            ------------------------------------------------------------------------------
            17:55:56,935 WARN [ExplodedJarVisitor] Exploded jar does not exists (ignored): file:../surgeonfish.jar
            17:55:56,935 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrGroups
            17:55:56,951 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrGroups on table pr_groups
            17:55:56,951 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrStaff
            17:55:56,951 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrStaff on table pr_staff
            17:55:56,966 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
            17:55:56,982 ERROR [STDERR] 317528 [http-127.0.0.1-8080-1] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{}
            17:55:56,982 ERROR [STDERR] 317528 [http-127.0.0.1-8080-1] INFO org.hibernate.connection.DatasourceConnectionProvider - Using datasource: java:/time_reporting_d
            ata_source
            17:55:56,998 ERROR [STDERR] 317544 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.1.12-beta-community-nt
            17:55:56,998 ERROR [STDERR] 317544 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-
            java-5.1.6 ( Revision: ${svn.Revision} )
            17:55:56,998 ERROR [STDERR] 317544 [http-127.0.0.1-8080-1] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
            17:55:56,998 ERROR [STDERR] 317544 [http-127.0.0.1-8080-1] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.ejb.tr
            ansaction.JoinableCMTTransactionFactory
            17:55:57,013 ERROR [STDERR] 317559 [http-127.0.0.1-8080-1] INFO org.hibernate.transaction.TransactionManagerLookupFactory - instantiating TransactionManagerLook
            up: org.hibernate.transaction.JBossTransactionManagerLookup
            17:55:57,013 ERROR [STDERR] 317559 [http-127.0.0.1-8080-1] INFO org.hibernate.transaction.TransactionManagerLookupFactory - instantiated TransactionManagerLooku
            p
            17:55:57,013 ERROR [STDERR] 317559 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
            17:55:57,029 ERROR [STDERR] 317575 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
            17:55:57,029 ERROR [STDERR] 317575 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
            17:55:57,029 ERROR [STDERR] 317575 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
            17:55:57,029 ERROR [STDERR] 317575 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
            17:55:57,029 ERROR [STDERR] 317575 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
            17:55:57,044 ERROR [STDERR] 317590 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
            17:55:57,044 ERROR [STDERR] 317590 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
            17:55:57,044 ERROR [STDERR] 317590 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
            17:55:57,044 ERROR [STDERR] 317590 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
            17:55:57,044 ERROR [STDERR] 317590 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
            17:55:57,044 ERROR [STDERR] 317590 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
            17:55:57,060 ERROR [STDERR] 317606 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFa
            ctory
            17:55:57,060 ERROR [STDERR] 317606 [http-127.0.0.1-8080-1] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
            17:55:57,060 ERROR [STDERR] 317606 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
            17:55:57,060 ERROR [STDERR] 317606 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: enabled
            17:55:57,060 ERROR [STDERR] 317606 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
            17:55:57,076 ERROR [STDERR] 317622 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
            17:55:57,076 ERROR [STDERR] 317622 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingReg
            ionFactory
            17:55:57,076 ERROR [STDERR] 317622 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
            17:55:57,076 ERROR [STDERR] 317622 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
            17:55:57,076 ERROR [STDERR] 317622 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
            17:55:57,091 ERROR [STDERR] 317637 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
            17:55:57,091 ERROR [STDERR] 317637 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
            17:55:57,091 ERROR [STDERR] 317637 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
            17:55:57,091 ERROR [STDERR] 317637 [http-127.0.0.1-8080-1] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
            17:55:57,107 ERROR [STDERR] 317653 [http-127.0.0.1-8080-1] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
            17:55:57,138 ERROR [STDERR] 317684 [http-127.0.0.1-8080-1] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name confi
            gured
            17:55:57,154 ERROR [STDERR] 317700 [http-127.0.0.1-8080-1] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
            17:55:57,154 ERROR [STDERR] 317700 [http-127.0.0.1-8080-1] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
            17:55:57,169 ERROR [STDERR] 317715 [http-127.0.0.1-8080-1] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
            17:55:57,169 ERROR [STDERR] 317715 [http-127.0.0.1-8080-1] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{}



            --EXCEPTION STACKTRACE--
            ------------------------------------------------------------------------
            2008-06-17 17:25:40,256 ERROR [com.ao.utils.pojo.PrStaffHome] get failed
            java.lang.NullPointerException
            at com.ao.utils.pojo.PrStaffHome.findById(PrStaffHome.java:74)
            at com.ao.jdbc.DBSecurity.checkUserPassword(DBSecurity.java:104)
            at com.ao.timereport.servlet.TIMEController.doLogin(TIMEController.java:550)
            at com.ao.timereport.servlet.TIMEController.service(TIMEController.java:58)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            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:230)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
            at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
            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:446)
            at java.lang.Thread.run(Thread.java:595)
            2008-06-17 17:25:40,287 ERROR [STDERR] java.lang.NullPointerException
            2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.utils.pojo.PrStaffHome.findById(PrStaffHome.java:74)
            2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.jdbc.DBSecurity.checkUserPassword(DBSecurity.java:104)
            2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.timereport.servlet.TIMEController.doLogin(TIMEController.java:550)
            2008-06-17 17:25:40,303 ERROR [STDERR] at com.ao.timereport.servlet.TIMEController.service(TIMEController.java:58)
            2008-06-17 17:25:40,303 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            2008-06-17 17:25:40,303 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            2008-06-17 17:25:40,303 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            2008-06-17 17:25:40,318 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
            2008-06-17 17:25:40,334 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            2008-06-17 17:25:40,334 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            2008-06-17 17:25:40,334 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
            2008-06-17 17:25:40,334 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)

            • 3. Re: EntityManager Injection, Null Pointer Exception. (Sorry.
              Ramazan Pekin Newbie

              Is there any solution can you suggest? I cant still find the solution, I am looking internet resources but my configuration looks like ok.

              • 4. Re: EntityManager Injection, Null Pointer Exception. (Sorry.
                jaikiran pai Master

                 

                HERE ARE THE CONSOLE OUTLINE WHEN I DEPLOY THE APPLICATION:
                17:50:41,517 INFO [JmxKernelAbstraction] persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
                17:50:41,532 INFO [EJBContainer] STARTED EJB: com.atosorigin.utils.pojo.PrStaffHome ejbName: PrStaffHome


                This line shows that the EJB has been properly deployed with the Entity manager dependency resolved.

                WHEN I TRY IT I AM TAKING ERROR:
                ------------------------------------------------------------------------------
                17:55:56,935 WARN [ExplodedJarVisitor] Exploded jar does not exists (ignored): file:../surgeonfish.jar
                17:55:56,935 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrGroups
                17:55:56,951 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrGroups on table pr_groups
                17:55:56,951 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrStaff
                17:55:56,951 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrStaff on table pr_staff


                However this part of the log is strange. I don't know why the application/entities are being "redeployed" when you are accessing your application. What exactly do you do in this step? I mean how do you invoke the application? For some reason, the application is getting redeployed.

                I see the following commented out portion in the EJB that you posted. Are you sure the class file that has been deployed also has this part commented?


                /*
                EntityManagerFactory emf = Persistence.createEntityManagerFactory("time_report_persistence_context");
                EntityManager em = emf.createEntityManager();
                PrStaff instance1 = em.find(PrStaff.class, id);
                ---this lines working without any error...---
                */



                • 5. Re: EntityManager Injection, Null Pointer Exception.
                  Ramazan Pekin Newbie

                  Hi, thanks for your reply.

                  I have tried a lot of possibilities. Yes, you right, at the sended log, the commented part not commented and have been worked together, but when I was trying the code parts separately, I was taking same error.

                  Now I am sending again the logs,

                  First of all deployment logs:
                  ----------------------------------------------------------------
                  14:18:02,714 INFO [TomcatDeployer] undeploy, ctxPath=/surgeonfish, warUrl=.../tmp/deploy/tmp25580surgeonfish.ear-contents/surgeonfish-exp.war/
                  14:18:02,730 INFO [EJBContainer] STOPPED EJB: com.atosorigin.utils.pojo.PrGroupsHome ejbName: PrGroupsHome
                  14:18:02,730 WARN [JmxKernelAbstraction] jboss.j2ee:ear=surgeonfish.ear,jar=surgeonfish.jar,name=PrGroupsHome,service=EJB3 is not registered
                  14:18:02,730 INFO [EJBContainer] STOPPED EJB: com.atosorigin.utils.pojo.PrStaffHome ejbName: PrStaffHome
                  14:18:02,730 WARN [JmxKernelAbstraction] jboss.j2ee:ear=surgeonfish.ear,jar=surgeonfish.jar,name=PrStaffHome,service=EJB3 is not registered
                  14:18:02,730 INFO [PersistenceUnitDeployment] Stopping persistence unit persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
                  14:18:02,745 ERROR [STDERR] 6708532 [ScannerThread] INFO org.hibernate.impl.SessionFactoryImpl - closing
                  14:18:02,745 ERROR [STDERR] 6708532 [ScannerThread] INFO org.hibernate.impl.SessionFactoryObjectFactory - Unbinding factory from JNDI name: persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,un
                  itName=time_report_persistence_context
                  14:18:02,745 ERROR [STDERR] 6708532 [ScannerThread] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.nam
                  ing.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
                  14:18:02,745 ERROR [STDERR] 6708532 [ScannerThread] INFO org.hibernate.impl.SessionFactoryObjectFactory - Unbound factory from JNDI name: persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unit
                  Name=time_report_persistence_context
                  14:18:02,761 ERROR [STDERR] 6708548 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
                  14:18:02,761 ERROR [STDERR] 6708548 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
                  14:18:02,761 ERROR [STDERR] 6708548 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
                  14:18:02,761 WARN [JmxKernelAbstraction] persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context is not registered
                  14:18:02,777 INFO [ConnectionFactoryBindingService] Unbound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=time_reporting_data_source' from JNDI name 'java:time_reporting_data_source'
                  14:18:02,870 INFO [EARDeployer] Undeploying J2EE application, destroy step: file:/C:/jboss/server/default/deploy/surgeonfish.ear
                  14:18:02,870 INFO [EARDeployer] Undeployed J2EE application: file:/C:/jboss/server/default/deploy/surgeonfish.ear
                  14:18:02,886 INFO [EARDeployer] Init J2EE application: file:/C:/jboss/server/default/deploy/surgeonfish.ear
                  14:18:03,994 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=time_reporting_data_source' to JNDI name 'java:time_reporting_data_source'
                  14:18:03,994 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.entity.PersistenceUnitDeployment
                  14:18:03,994 INFO [JmxKernelAbstraction] installing MBean: persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context with dependencies:
                  14:18:04,010 INFO [JmxKernelAbstraction] jboss.jca:name=time_reporting_data_source,service=DataSourceBinding
                  14:18:04,010 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
                  14:18:04,072 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrGroups
                  14:18:04,072 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrGroups on table pr_groups
                  14:18:04,072 INFO [AnnotationBinder] Binding entity from annotated class: com.atosorigin.utils.pojo.PrStaff
                  14:18:04,072 INFO [EntityBinder] Bind entity com.atosorigin.utils.pojo.PrStaff on table pr_staff
                  14:18:04,088 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
                  14:18:04,119 ERROR [STDERR] 6709906 [ScannerThread] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectio
                  nProvider
                  14:18:04,119 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
                  14:18:04,135 ERROR [STDERR] 6709922 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.1.12-beta-community-nt
                  14:18:04,135 ERROR [STDERR] 6709922 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
                  14:18:04,135 ERROR [STDERR] 6709922 [ScannerThread] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
                  14:18:04,150 ERROR [STDERR] 6709937 [ScannerThread] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
                  14:18:04,150 ERROR [STDERR] 6709937 [ScannerThread] INFO org.hibernate.transaction.TransactionManagerLookupFactory - instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionM
                  anagerLookup
                  14:18:04,150 ERROR [STDERR] 6709937 [ScannerThread] INFO org.hibernate.transaction.TransactionManagerLookupFactory - instantiated TransactionManagerLookup
                  14:18:04,150 ERROR [STDERR] 6709937 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
                  14:18:04,150 ERROR [STDERR] 6709937 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
                  14:18:04,150 ERROR [STDERR] 6709937 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
                  14:18:04,166 ERROR [STDERR] 6709953 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
                  14:18:04,182 ERROR [STDERR] 6709969 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
                  14:18:04,182 ERROR [STDERR] 6709969 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
                  14:18:04,182 ERROR [STDERR] 6709969 [ScannerThread] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
                  14:18:04,182 ERROR [STDERR] 6709969 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
                  14:18:04,182 ERROR [STDERR] 6709969 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: enabled
                  14:18:04,182 ERROR [STDERR] 6709969 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
                  14:18:04,182 ERROR [STDERR] 6709969 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
                  14:18:04,197 ERROR [STDERR] 6709984 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
                  14:18:04,197 ERROR [STDERR] 6709984 [ScannerThread] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.HashtableCacheProvider
                  14:18:04,197 ERROR [STDERR] 6709984 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
                  14:18:04,197 ERROR [STDERR] 6709984 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Cache region prefix: surgeonfish_ear,surgeonfish_jar,time_report_persistence_context
                  14:18:04,197 ERROR [STDERR] 6709984 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
                  14:18:04,197 ERROR [STDERR] 6709984 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
                  14:18:04,197 ERROR [STDERR] 6709984 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
                  14:18:04,213 ERROR [STDERR] 6710000 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
                  14:18:04,213 ERROR [STDERR] 6710000 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
                  14:18:04,213 ERROR [STDERR] 6710000 [ScannerThread] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
                  14:18:04,213 ERROR [STDERR] 6710000 [ScannerThread] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
                  14:18:04,260 ERROR [STDERR] 6710047 [ScannerThread] INFO org.hibernate.impl.SessionFactoryObjectFactory - Factory name: persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_p
                  ersistence_context
                  14:18:04,260 ERROR [STDERR] 6710047 [ScannerThread] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.nam
                  ing.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
                  14:18:04,260 ERROR [STDERR] 6710047 [ScannerThread] INFO org.hibernate.impl.SessionFactoryObjectFactory - Bound factory to JNDI name: persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName
                  =time_report_persistence_context
                  14:18:04,275 ERROR [STDERR] 6710062 [ScannerThread] WARN org.hibernate.impl.SessionFactoryObjectFactory - InitialContext did not implement EventContext
                  14:18:04,275 ERROR [STDERR] 6710062 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
                  14:18:04,275 ERROR [STDERR] 6710062 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
                  14:18:04,306 ERROR [STDERR] 6710093 [ScannerThread] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
                  14:18:04,306 ERROR [STDERR] 6710093 [ScannerThread] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.nam
                  ing.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
                  14:18:04,306 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
                  14:18:04,322 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=surgeonfish.ear,jar=surgeonfish.jar,name=PrGroupsHome,service=EJB3 with dependencies:
                  14:18:04,322 INFO [JmxKernelAbstraction] persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
                  14:18:04,338 INFO [EJBContainer] STARTED EJB: com.atosorigin.utils.pojo.PrGroupsHome ejbName: PrGroupsHome
                  14:18:04,353 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
                  14:18:04,353 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=surgeonfish.ear,jar=surgeonfish.jar,name=PrStaffHome,service=EJB3 with dependencies:
                  14:18:04,353 INFO [JmxKernelAbstraction] persistence.units:ear=surgeonfish.ear,jar=surgeonfish.jar,unitName=time_report_persistence_context
                  14:18:04,369 INFO [EJBContainer] STARTED EJB: com.atosorigin.utils.pojo.PrStaffHome ejbName: PrStaffHome
                  14:18:04,385 INFO [EJB3Deployer] Deployed: file:/C:/jboss/server/default/tmp/deploy/tmp25581surgeonfish.ear-contents/surgeonfish.jar
                  14:18:04,385 INFO [TomcatDeployer] deploy, ctxPath=/surgeonfish, warUrl=.../tmp/deploy/tmp25581surgeonfish.ear-contents/surgeonfish-exp.war/
                  14:18:04,509 INFO [EARDeployer] Started J2EE application: file:/C:/jboss/server/default/deploy/surgeonfish.ear

                  the bean code is exactly this:

                  @Stateless
                  @Local(value=PrStaffInterface.class)
                  public class PrStaffHome {
                  
                   private static final Log log = LogFactory.getLog(PrStaffHome.class);
                  
                   @PersistenceContext(unitName="time_report_persistence_context")
                   private EntityManager entityManager;
                  
                   public PrStaff findById(Integer id) {
                   log.debug("getting PrStaff instance with id: " + id);
                   try {
                   System.out.println("-------------entityManager-------------:"+entityManager);
                   PrStaff instance = entityManager.find(PrStaff.class, id);
                   log.debug("get successful");
                   return instance;
                   } catch (RuntimeException re) {
                   log.error("get failed", re);
                   throw re;
                   }
                   }
                  }
                  



                  And the code's log:

                  14:31:39,747 INFO [STDOUT] -------------entityManager-------------:null
                  14:31:39,763 ERROR [PrStaffHome] get failed
                  java.lang.NullPointerException
                  at com.atosorigin.utils.pojo.PrStaffHome.findById(PrStaffHome.java:75)
                  at com.atosorigin.jdbc.DBSecurity.checkUserPassword(DBSecurity.java:102)
                  at com.atosorigin.timereport.servlet.TIMEController.doLogin(TIMEController.java:550)
                  at com.atosorigin.timereport.servlet.TIMEController.service(TIMEController.java:58)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                  at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                  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:230)
                  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                  at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                  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:446)
                  at java.lang.Thread.run(Thread.java:595)
                  14:31:39,763 ERROR [STDERR] java.lang.NullPointerException
                  14:31:39,763 ERROR [STDERR] at com.atosorigin.utils.pojo.PrStaffHome.findById(PrStaffHome.java:75)
                  14:31:39,763 ERROR [STDERR] at com.atosorigin.jdbc.DBSecurity.checkUserPassword(DBSecurity.java:102)
                  14:31:39,763 ERROR [STDERR] at com.atosorigin.timereport.servlet.TIMEController.doLogin(TIMEController.java:550)
                  14:31:39,763 ERROR [STDERR] at com.atosorigin.timereport.servlet.TIMEController.service(TIMEController.java:58)
                  14:31:39,763 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                  14:31:39,763 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                  14:31:39,763 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                  14:31:39,763 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                  14:31:39,763 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                  14:31:39,763 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                  14:31:39,763 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                  14:31:39,763 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                  14:31:39,763 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                  14:31:39,763 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)


                  I have tried the bean by this code, it was triggered by user request through servlet:
                  public class DBSecurity {
                   public boolean checkUserPassword(String username, String password) throws Exception {
                   PrStaffHome prStaffHome = new PrStaffHome();
                   PrStaff prStaff = prStaffHome.findById(new Integer(username));
                   }
                  }
                  


                  I am so thanksfull for your helps, I have stucked at this point.

                  • 6. Re: EntityManager Injection, Null Pointer Exception. (Sorry.
                    jaikiran pai Master

                     

                    PrStaffHome prStaffHome = new PrStaffHome();


                    This is incorrect. You should not be instantiating a EJB in your code. Instead you should be doing a "lookup" of the bean. See my reply dated Mon May 26, 2008 11:02 AM in one other similar post at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=136213

                    • 7. Re: EntityManager Injection, Null Pointer Exception. (Sorry.
                      Ramazan Pekin Newbie

                      I am so thankful for your helps, finally it worked.

                      This is the final situation:

                      I have changed ejb call part like that:

                      Context context = new InitialContext();
                      PrStaffInterface prstaff = (PrStaffInterface)context.lookup("surgeonfish/PrStaffHome/local");
                      prstaff.findById(new Integer(username));
                      


                      And I have changed little part of persistence.xml

                      <persistence>
                       <persistence-unit name="time_report_persistence_context">
                       <provider>org.hibernate.ejb.HibernatePersistence</provider>
                       <jta-data-source>java:/time_reporting_data_source</jta-data-source>
                       <jar-file>/surgeonfish.jar</jar-file>-->this place changed
                       <properties>
                       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                       <property name="hibernate.show_sql" value="true"/>
                       <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
                       <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                       </properties>
                       </persistence-unit>
                      </persistence>
                      


                      I have thought, I dont need to lookup. The ejb container is injecting, or intercepting at the object initialization and giving already created ejb object.

                      Thanks again.