13 Replies Latest reply on Feb 12, 2010 6:57 PM by bb bb

    I get NullPointerException on entityManager.persist(obj)

    Diogo Azevedo Newbie
      I'm working on a small application with seam framework and I'm having trouble when I use the command entityManager.persist (usuario);
      the server returns NullPointerException in method usuarioAction.salvarUsuario() why?

      20:33:05,018 ERROR [applicati|on] ja|va.lang.NullPointerException
      javax.faces.el.EvaluationException: java.lang.NullPointerException



      Myclass UsuarioAction.java

      import java.util.List;
      import javax.persistence.EntityManager;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.international.StatusMessage.Severity;

      import br.odebrecht.entity.Usuario;

      @Name("usuarioAction")
      @Scope(ScopeType.CONVERSATION)
      public class UsuarioAction {

      @In(required=false)
      @Out(required=false)
      private Usuario usuario;

      @In
      private EntityManager entityManager;

      @Out
      FacesMessages facesMessages;

      @DataModel
      List<Usuario> listaUsuario;

      @DataModelSelection
      @Out(required=false)
      Usuario usuarioSelecionado;

      public void salvarUsuario(){
      try {
      entityManager.persist(usuario); //Here NullPointerException happens

      } catch (Exception e) {
      facesMessages.add(Severity.ERROR,"Erro ao salvar informações!!! ");
      }
      facesMessages.add(Severity.INFO,"Operação realizada com sucesso!!!");
      }
      }



      usuario.xhtml call the salvarUsuario method

      <h:commandButton id="salvar" action="#{usuarioAction.salvarUsuario}" value="Salvar" />


      Someone help me ..

      thanks for attention

      ``

        • 1. Re: I get NullPointerException on entityManager.persist(obj)
          bb bb Master

          Can you attach the full exception log and Usuario entity. thx.

          • 2. Re: I get NullPointerException on entityManager.persist(obj)
            Bernard Labno Master

            I guess you have invalid setup in config.xml. Show it for further investigation.

            • 3. Re: I get NullPointerException on entityManager.persist(obj)
              Diogo Azevedo Newbie
              thanks for your attention



              07:46:37,145 INFO  [Version] Hibernate EntityManager 3.2.1.GA
              07:46:37,167 INFO  [Version] Hibernate Annotations 3.2.1.GA
              07:46:37,181 INFO  [Environment] Hibernate 3.2.4.sp1
              07:46:37,196 INFO  [Environment] hibernate.properties not found
              07:46:37,199 INFO  [Environment] Bytecode provider name : javassist
              07:46:37,204 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling
              07:46:37,342 INFO  [AnnotationBinder] Binding entity from annotated class: br.odebrecht.entity.Usuario
              07:46:37,348 INFO  [QueryBinder] Binding Named query: usuario.findByNameAndPassword => select u from Usuario u where u.nome = :nome and u.password = :password
              07:46:37,348 INFO  [QueryBinder] Binding Named query: usuario.findByName => select u from Usuario u order by u.nome
              07:46:37,370 INFO  [EntityBinder] Bind entity br.odebrecht.entity.Usuario on table Usuario
              07:46:37,659 INFO  [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
              07:46:37,659 INFO  [DatasourceConnectionProvider] Using datasource: java:/ControleManutencaoDatasource
              07:46:37,772 INFO  [SettingsFactory] RDBMS: Microsoft SQL Server, version: 9.00.4053
              07:46:37,772 INFO  [SettingsFactory] JDBC driver: Microsoft SQL Server 2005 JDBC Driver, version: 1.0.809.102
              07:46:37,784 INFO  [Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect
              07:46:37,788 INFO  [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
              07:46:37,790 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
              07:46:37,791 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
              07:46:37,791 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): disabled
              07:46:37,791 INFO  [SettingsFactory] Automatic session close at end of transaction: disabled
              07:46:37,791 INFO  [SettingsFactory] Scrollable result sets: enabled
              07:46:37,791 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
              07:46:37,791 INFO  [SettingsFactory] Connection release mode: auto
              07:46:37,792 INFO  [SettingsFactory] Default batch fetch size: 1
              07:46:37,792 INFO  [SettingsFactory] Generate SQL with comments: disabled
              07:46:37,792 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
              07:46:37,792 INFO  [SettingsFactory] Order SQL inserts for batching: disabled
              07:46:37,792 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
              07:46:37,794 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
              07:46:37,794 INFO  [SettingsFactory] Query language substitutions: {}
              07:46:37,794 INFO  [SettingsFactory] JPA-QL strict compliance: enabled
              07:46:37,794 INFO  [SettingsFactory] Second-level cache: enabled
              07:46:37,794 INFO  [SettingsFactory] Query cache: disabled
              07:46:37,794 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.NoCacheProvider
              07:46:37,794 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
              07:46:37,794 INFO  [SettingsFactory] Structured second-level cache entries: disabled
              07:46:37,797 INFO  [SettingsFactory] Echoing all SQL to stdout
              07:46:37,798 INFO  [SettingsFactory] Statistics: disabled
              07:46:37,798 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
              07:46:37,798 INFO  [SettingsFactory] Default entity-mode: pojo
              07:46:37,798 INFO  [SettingsFactory] Named query checking : enabled
              07:46:37,817 INFO  [SessionFactoryImpl] building session factory
              07:46:37,934 INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
              07:46:37,936 INFO  [SchemaUpdate] Running hbm2ddl schema update
              07:46:37,936 INFO  [SchemaUpdate] fetching database metadata
              07:46:37,941 INFO  [SchemaUpdate] updating schema
              07:46:38,023 INFO  [TableMetadata] table found: Gerenciamento.dbo.Usuario
              07:46:38,023 INFO  [TableMetadata] columns: [id, perfil, nome, password]
              07:46:38,023 INFO  [TableMetadata] foreign keys: []
              07:46:38,023 INFO  [TableMetadata] indexes: [pk__usuario__0519c6af, uq__usuario__060deae8]
              07:46:38,023 INFO  [SchemaUpdate] schema update complete
              07:46:38,024 INFO  [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
              07:46:38,156 INFO  [SeamFilter] Initializing filter: org.jboss.seam.web.hotDeployFilter
              07:46:38,156 INFO  [SeamFilter] Initializing filter: org.jboss.seam.web.loggingFilter
              07:46:38,156 INFO  [SeamFilter] Initializing filter: org.jboss.seam.web.ajax4jsfFilter
              07:46:38,172 INFO  [CacheManager] Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
              07:46:38,174 INFO  [LRUMapCacheFactory] Creating LRUMap cache instance using parameters: {facelets.DEVELOPMENT=true, org.richfaces.SKIN=ruby, com.sun.faces.injectionProvider=org.jboss.web.jsf.integration.injection.JBossInjectionProvider, javax.faces.DEFAULT_SUFFIX=.xhtml}
              07:46:38,174 INFO  [LRUMapCacheFactory] Creating LRUMap cache instance of default capacity
              07:46:38,185 INFO  [CacheManager] Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
              07:46:38,185 INFO  [LRUMapCacheFactory] Creating LRUMap cache instance using parameters: {facelets.DEVELOPMENT=true, org.richfaces.SKIN=ruby, com.sun.faces.injectionProvider=org.jboss.web.jsf.integration.injection.JBossInjectionProvider, javax.faces.DEFAULT_SUFFIX=.xhtml}
              07:46:38,185 INFO  [LRUMapCacheFactory] Creating LRUMap cache instance of default capacity
              07:46:38,185 INFO  [SeamFilter] Initializing filter: org.jboss.seam.web.redirectFilter
              07:46:38,185 INFO  [SeamFilter] Initializing filter: org.jboss.seam.web.exceptionFilter
              07:46:38,185 INFO  [SeamFilter] Initializing filter: org.jboss.seam.web.multipartFilter
              07:46:38,185 INFO  [SeamFilter] Initializing filter: org.jboss.seam.web.identityFilter
              07:46:45,674 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jboss-seam-excel.jar!/META-INF/seam-excel.taglib.xml
              07:46:45,676 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jboss-seam-mail.jar!/META-INF/seam-mail.taglib.xml
              07:46:45,678 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jboss-seam-pdf.jar!/META-INF/seam-pdf.taglib.xml
              07:46:45,689 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jboss-seam-ui.jar!/META-INF/s.taglib.xml
              07:46:45,702 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-core.taglib.xml
              07:46:45,705 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-html.taglib.xml
              07:46:45,713 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-ui.taglib.xml
              07:46:45,720 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-core.taglib.xml
              07:46:45,723 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-fn.taglib.xml
              07:46:45,733 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/richfaces-ui.jar!/META-INF/a4j.taglib.xml
              07:46:45,735 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/richfaces-ui.jar!/META-INF/jsp.taglib.xml
              07:46:45,737 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/richfaces-ui.jar!/META-INF/ajax4jsf.taglib.xml
              07:46:45,771 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/richfaces-ui.jar!/META-INF/rich.taglib.xml
              07:46:45,774 ERROR [STDERR] Feb 11, 2010 7:46:45 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              INFO: Added Library from: jar:file:/C:/Workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_AS_4.2_Server/deploy/ControleManutencao.war/WEB-INF/lib/richfaces-ui.jar!/META-INF/richfaces.taglib.xml
              07:46:50,319 INFO  [Authenticator] authenticating admin
              07:47:03,111 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
              sourceId=frmUsuario:DSenha:inpSenha[severity=(ERROR 2), summary=(value is required), detail=(value is required)]
              sourceId=frmUsuario:DPerfil:j_id56[severity=(ERROR 2), summary=(value is required), detail=(value is required)]
              07:47:05,284 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
              sourceId=frmUsuario:DPerfil:j_id56[severity=(ERROR 2), summary=(value is required), detail=(value is required)]
              07:47:08,182 ERROR [application] java.lang.NullPointerException
              javax.faces.el.EvaluationException: java.lang.NullPointerException
                      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                      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.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                      at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
                      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
                      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                      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:182)
                      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                      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:619)
              Caused by: java.lang.NullPointerException
                      at br.odebrecht.action.UsuarioAction.salvarUsuario(UsuarioAction.java:45)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      at java.lang.reflect.Method.invoke(Method.java:597)
                      at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                      at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                      at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                      at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                      at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                      at br.odebrecht.action.UsuarioAction_$$_javassist_seam_4.salvarUsuario(UsuarioAction_$$_javassist_seam_4.java)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      at java.lang.reflect.Method.invoke(Method.java:597)
                      at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
                      at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
                      at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                      at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                      at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                      at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                      ... 51 more
              07:47:08,183 WARN  [lifecycle] #{usuarioAction.salvarUsuario}: java.lang.NullPointerException
              javax.faces.FacesException: #{usuarioAction.salvarUsuario}: java.lang.NullPointerException
                      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
                      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.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                      at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
                      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
                      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                      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:182)
                      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                      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:619)
              Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
                      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                      ... 50 more
              Caused by: java.lang.NullPointerException
                      at br.odebrecht.action.UsuarioAction.salvarUsuario(UsuarioAction.java:45)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      at java.lang.reflect.Method.invoke(Method.java:597)
                      at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                      at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                      at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                      at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                      at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                      at br.odebrecht.action.UsuarioAction_$$_javassist_seam_4.salvarUsuario(UsuarioAction_$$_javassist_seam_4.java)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                      at java.lang.reflect.Method.invoke(Method.java:597)
                      at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
                      at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
                      at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                      at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                      at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                      at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                      ... 51 more
              07:47:08,184 ERROR [lifecycle] JSF1054: (Phase ID: INVOKE_APPLICATION 5, View ID: /usuario.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@114382d]
              07:47:08,384 ERROR [STDERR] Feb 11, 2010 7:47:08 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
              • 4. Re: I get NullPointerException on entityManager.persist(obj)
                Diogo Azevedo Newbie
                My entity Usuario class


                package br.odebrecht.entity;

                import java.io.Serializable;
                import javax.persistence.Column;
                import javax.persistence.Entity;
                import javax.persistence.EnumType;
                import javax.persistence.Enumerated;
                import javax.persistence.GeneratedValue;
                import javax.persistence.GenerationType;
                import javax.persistence.Id;
                import javax.persistence.NamedQueries;
                import javax.persistence.NamedQuery;
                import org.hibernate.validator.Length;
                import org.hibernate.validator.NotNull;
                import org.jboss.seam.annotations.Name;
                import br.odebrecht.entity.Perfil;

                @Entity
                @Name("usuario")
                @NamedQueries({
                     @NamedQuery(name="usuario.findByNameAndPassword",query="select u from Usuario u where u.nome = :nome and u.password = :password"),
                     @NamedQuery(name="usuario.findByName",query="select u from Usuario u order by u.nome")
                })
                public class Usuario implements Serializable {

                     private static final long serialVersionUID = -8461239822219559800L;
                     
                     @Id
                     @GeneratedValue(strategy=GenerationType.AUTO)
                     @NotNull
                     private Integer id;
                     
                     @Column(nullable=false,length=100,unique=true)
                     @Length(min=5, max=50, message="O nome deverá ter entre 5 e 50 caracteres...")
                     @NotNull
                     private String nome;
                     
                     @Length(min=5, max=10, message="A senha deverá ter entre 5 e 10 caracteres...")
                     @NotNull
                     private String password;
                     
                     @Enumerated(EnumType.ORDINAL)
                     @NotNull
                     private Perfil perfil;

                     public Integer getId() {
                          return id;
                     }

                     public void setId(Integer id) {
                          this.id = id;
                     }

                     public String getNome() {
                          return nome;
                     }

                     public void setNome(String nome) {
                          this.nome = nome;
                     }

                     public String getPassword() {
                          return password;
                     }

                     public void setPassword(String password) {
                          this.password = password;
                     }

                     public Perfil getPerfil() {
                          return perfil;
                     }

                     public void setPerfil(Perfil perfil) {
                          this.perfil = perfil;
                     }

                     @Override
                     public int hashCode() {
                          final int prime = 31;
                          int result = 1;
                          result = prime * result + ((id == null) ? 0 : id.hashCode());
                          result = prime * result + ((nome == null) ? 0 : nome.hashCode());
                          result = prime * result
                                    + ((password == null) ? 0 : password.hashCode());
                          result = prime * result + ((perfil == null) ? 0 : perfil.hashCode());
                          return result;
                     }

                     @Override
                     public boolean equals(Object obj) {
                          if (this == obj)
                               return true;
                          if (obj == null)
                               return false;
                          if (getClass() != obj.getClass())
                               return false;
                          Usuario other = (Usuario) obj;
                          if (id == null) {
                               if (other.id != null)
                                    return false;
                          } else if (!id.equals(other.id))
                               return false;
                          if (nome == null) {
                               if (other.nome != null)
                                    return false;
                          } else if (!nome.equals(other.nome))
                               return false;
                          if (password == null) {
                               if (other.password != null)
                                    return false;
                          } else if (!password.equals(other.password))
                               return false;
                          if (perfil == null) {
                               if (other.perfil != null)
                                    return false;
                          } else if (!perfil.equals(other.perfil))
                               return false;
                          return true;
                     }


                     
                     
                     //@OneToMany(mappedBy="usuarios",fetch=FetchType.EAGER)
                     //private List<Chamado> chamados;
                     

                }


                • 5. Re: I get NullPointerException on entityManager.persist(obj)
                  Arbi Sookazian Master

                  There is a NPE being thrown here: UsuarioAction.java:45


                  what code is at that line??

                  • 6. Re: I get NullPointerException on entityManager.persist(obj)
                    Diogo Azevedo Newbie

                    thanks for your attention



                    line 45 is that:



                    public void salvarUsuario(){
                    try {
                    entityManager.persist(usuario); //Here NullPointerException happens


                    } catch (Exception e) {
                    facesMessages.add(Severity.ERROR,Erro ao salvar informações!!! );  //  here line 45
                    }
                    facesMessages.add(Severity.INFO,Operação realizada com sucesso!!!);
                    }

                    • 7. Re: I get NullPointerException on entityManager.persist(obj)
                      Shervin Asgari Master

                      Try putting breakpoint and investigate the usuario object. See if any values are null.
                      If you dont know how to use breakpoint, just generate a toString and usario object and print it before you are running persist.
                      Also, avoid using facesMessage. Use StatusMessages instead.

                      • 8. Re: I get NullPointerException on entityManager.persist(obj)
                        Diogo Azevedo Newbie

                        thanks Shervin for you attention ... but every atributes of usuario object are populated.... 




                        and my entityManager is not null too ...

                        • 10. Re: I get NullPointerException on entityManager.persist(obj)
                          Diogo Azevedo Newbie
                          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                          <ui:composition
                                xmlns="http://www.w3.org/1999/xhtml"
                                xmlns:h="http://java.sun.com/jsf/html"
                                xmlns:f="http://java.sun.com/jsf/core"
                                xmlns:ui="http://java.sun.com/jsf/facelets"
                                xmlns:rich="http://richfaces.org/rich"
                                xmlns:a4j="http://richfaces.org/a4j"
                                xmlns:s="http://jboss.com/products/seam/taglib"
                                template="/layout/template.xhtml">
                               
                                  <ui:define name="body">
                                    
                                      <h:form id="frmUsuario" >
                                             <rich:panel id="campos"  >
                                              <!-- Efeitos                       -->
                                                  <f:facet name="header" >Campos</f:facet>
                                              <!--   -->
                                             
                                              <h:panelGrid columns="1">
                                                  <s:decorate id="DNome" template="/layout/edit.xhtml">
                                                      <ui:define name="label">Nome:</ui:define>
                                                      <h:inputText id="inpNome" required="true" value="#{usuario.nome}" style="width:300px">
                                                       <a4j:support event="onblur" reRender="DNome"/>
                                                      </h:inputText>
                                                  </s:decorate>

                                                  <s:decorate id="DSenha" template="/layout/edit.xhtml">
                                                      <ui:define name="label">Senha:</ui:define>
                                                      <h:inputText id="inpSenha" required="true" value="#{usuario.password}" style="width:200px">
                                                       <a4j:support event="onblur" reRender="DSenha"/>
                                                      </h:inputText>
                                                  </s:decorate>
                                                 
                                                   <s:decorate id="DPerfil" template="/layout/edit.xhtml">
                                                       <ui:define name="label">Perfil:</ui:define>
                                                        <h:selectOneMenu value="#{usuario.perfil}" style="width:150px" >
                                                            <s:selectItems var="item" value="#{perfilUsuario}" noSelectionLabel="Selecione ..."
                                                                label="#{item.descricao}" />
                                                            <s:convertEnum />
                                                        </h:selectOneMenu>
                                                   </s:decorate>
                                                 
                                                  <h:commandButton id="salvar" action="#{usuarioAction.salvarUsuario}" value="Salvar" />
                                              </h:panelGrid>

                                             </rich:panel>
                                         
                                      </h:form>                  
                                  </ui:define>


                          </ui:composition>
                          • 11. Re: I get NullPointerException on entityManager.persist(obj)
                            bb bb Master

                            Can you attach your component.xml and persistence.xml ??


                            thx.

                            • 12. Re: I get NullPointerException on entityManager.persist(obj)
                              Diogo Azevedo Newbie
                              my component.xml

                              <?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 debug="true" jndi-pattern="@jndiPattern@"/>

                                 <core:manager concurrent-request-timeout="500"
                                               conversation-timeout="120000"
                                               conversation-id-parameter="cid"
                                               parent-conversation-id-parameter="pid"/>

                                 <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
                                 <web:hot-deploy-filter url-pattern="*.seam"/>

                                 <persistence:managed-persistence-context name="entityManager"
                                                                   auto-create="true"
                                                        entity-manager-factory="#{ControleManutencaoEntityManagerFactory}"/>

                                 <persistence:entity-manager-factory name="ControleManutencaoEntityManagerFactory"
                                                    persistence-unit-name="ControleManutencao"/>




                                 <drools:rule-base name="securityRules">
                                    <drools:rule-files><value>/security.drl</value></drools:rule-files>
                                 </drools:rule-base>

                                 <security:rule-based-permission-resolver security-rules="#{securityRules}"/>

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

                                 <event type="org.jboss.seam.security.notLoggedIn">
                                    <action execute="#{redirect.captureCurrentView}"/>
                                 </event>
                                 <event type="org.jboss.seam.security.loginSuccessful">
                                    <action execute="#{redirect.returnToCapturedView}"/>
                                 </event>

                                 <mail:mail-session host="localhost" port="25"/>

                                 <!-- For use with jBPM pageflow or process management -->
                                 <!--
                                 <bpm:jbpm>
                                    <bpm:process-definitions></bpm:process-definitions>
                                    <bpm:pageflow-definitions></bpm:pageflow-definitions>
                                 </bpm:jbpm>
                                 -->

                              </components>



                              my persist.xml


                              <?xml version="1.0" encoding="UTF-8"?>
                              <!-- Persistence deployment descriptor for dev profile -->
                              <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                                           version="1.0">
                                          
                                 <persistence-unit name="ControleManutencao" transaction-type="JTA">
                                    <provider>org.hibernate.ejb.HibernatePersistence</provider>
                                    <jta-data-source>java:/ControleManutencaoDatasource</jta-data-source>
                                    <properties>
                                       <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
                                       <property name="hibernate.hbm2ddl.auto" value="update"/>
                                       <property name="hibernate.show_sql" value="true"/>
                                       <property name="hibernate.format_sql" value="true"/>
                                       <!-- Only relevant if Seam is loading the persistence unit (Java SE bootstrap) -->
                                       <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                                    </properties>
                                 </persistence-unit>
                                 
                              </persistence>

                              • 13. Re: I get NullPointerException on entityManager.persist(obj)
                                bb bb Master
                                Instead of this:



                                <persistence:managed-persistence-context name="entityManager"
                                                                     auto-create="true"
                                                          entity-manager-factory="#{ControleManutencaoEntityManagerFactory}"/>

                                   <persistence:entity-manager-factory name="ControleManutencaoEntityManagerFactory"
                                                      persistence-unit-name="ControleManutencao"/>



                                You should use this:

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


                                and modify the persistence.xml to the folloeing way:

                                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
                                               <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                                               <property name="jboss.entity.manager.factory.jndi.name" value="java:/xxxEntityManagerFactory" />