6 Replies Latest reply on Oct 9, 2012 4:29 PM by Luan Garcia

    java.lang.NullPointerException when using EntityManager on Seam

    Luan Garcia Newbie

      Hello all.

       

      I'm new to Seam framework and I'm having some issues. I always try to solve problemas searching first, but I'm not being able to do that this time.

       

      I'm trying to populate a selectOneMenu compoent, but it isn't as easy as it seems

       

      Here is the code:

       

       

      @Name("collaboration")
      public class CollaborationHome 
      {
      
      
          EntityManager em;
      
      
                @Out(required = false)
                List<Ontology> ontologyList;
      
      
                @Factory("ontologies")
                public void getOntologies()
                {
      
      
                                    ontologyList =  (List<Ontology>) em.createQuery("from Ontology").getResultList();
      
      
                }
        
                private Ontology ontology;
        
                public Ontology getOntology()
                {
                          return ontology;
                }
        
                public void setOntology(Ontology o)
                {
                          this.ontology = o;
                }
        
      }
      
      

       

      And here is the xhtml:

       

      <!DOCTYPE composition 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:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml">
      
      
                <ui:define name="body">
                          <div>
                                    <h:form>
                                              <rich:panel>
                                                        <f:facet name="header">Concepts:</f:facet>
                                                        <h:outputLabel value="Ontology:" ></h:outputLabel>
                                                        <h:selectOneMenu id="cbOntology" value="#{collaboration.ontology}">
                                                                  <s:selectItems value="#{ontologies}" noSelectionLabel="Select an Ontology">
                                                                  </s:selectItems>
                                                        </h:selectOneMenu>
                                                        <h:commandButton id="btnLoadOntology" value="Load" action="submit()" />
                                                        </rich:panel>
                                    </h:form>
                          </div>
                </ui:define>
      
      
      </ui:composition>
      
      

       

      I'm having the following problem:

       

      java.lang.NullPointerException
       at org.domain.obaita.session.CollaborationHome.getOntologies(CollaborationHome.java:27)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       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 org.domain.obaita.session.CollaborationHome_$$_javassist_seam_19.getOntologies(CollaborationHome_$$_javassist_seam_19.java)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
       at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
       at org.jboss.seam.Component.getInstanceFromFactory(Component.java:2101)
       at org.jboss.seam.Component.getInstance(Component.java:2014)
       at org.jboss.seam.Component.getInstance(Component.java:1986)
       at org.jboss.seam.Component.getInstance(Component.java:1980)
       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
       at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
       at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
       at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
       at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:173)
       at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:200)
       at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
       at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at javax.faces.component.UISelectItems.getValue(UISelectItems.java:141)
       at org.jboss.seam.ui.component.UISelectItems.getValue(UISelectItems.java:161)
       at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:283)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:783)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:864)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:281)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200)
       at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195)
       at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:840)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
       at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:840)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
       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:206)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
       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:274)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
       at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)
       at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
       at java.lang.Thread.run(Unknown Source)
      

       

      Can't really figure why this is happening. I will post here my configuration files, maybe it helps.

       

      persistence.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="obaita" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/obaitaDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="update"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/obaitaEntityManagerFactory"/>
            </properties>
         </persistence-unit>
          
      </persistence>
      
      
      
      components.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"/>
      
      
         <!-- If you are still using JBoss 4, uncomment this to have your PU started -->
      <!--   <persistence:entity-manager-factory name="entityManagerFactory"-->
      <!--                      persistence-unit-name="obaita"/>-->
         <!-- If you are still using JBoss 4, uncomment this to have the entityManagerFactory ysed -->
      <!--   <persistence:managed-persistence-context name="entityManager" auto-create="true"-->
      <!--                          entity-manager-factory="#{entityManagerFactory}"/>-->
      
      
         <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                 persistence-unit-jndi-name="java:/obaitaEntityManagerFactory"/>
      
      
         <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"/>
         <!-- nem sei se funfa isso -->
         <!-- 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>
      
      

       

      If its worth to say, I've generated my project by the Seam Gen feature, so I didn't really configure anything so far.

       

      Please, any tips would be nice

        • 1. Re: java.lang.NullPointerException when using EntityManager on Seam
          Martin Kouba Master

          Hi Luan,

           

          I guess that NPE is thrown because of injection annotation is missing on EntityManager field in CollaborationHome  -> @In EntityManager em;

          1 of 1 people found this helpful
          • 2. Re: java.lang.NullPointerException when using EntityManager on Seam
            Luan Garcia Newbie

            Hi Martin, thanks for the help!

             

            I already tried the @In annotation, but I still have some errors.

             

            I've tried @In, @In(create=true) and @In(create=true, required=true). All give me the same error:

             GRAVE [facelets.viewhandler] Error Rendering View[/Collaboration2.xhtml]: javax.faces.FacesException: javax.el.ELException: /Collaboration2.xhtml @17,73 value="#{collaboration.ontology}": org.jboss.seam.RequiredException: @In attribute requires non-null value: collaboration.em
                      at javax.faces.component.UIOutput.getValue(UIOutput.java:187) [:1.2_15-20100816-SNAPSHOT]
                      at org.jboss.seam.ui.component.UISelectItems.getParentValue(UISelectItems.java:293) [:2.2.2.Final]
                      at org.jboss.seam.ui.component.UISelectItems.isShowNoSelectionLabel(UISelectItems.java:256) [:2.2.2.Final]
                      at org.jboss.seam.ui.component.UISelectItems.noSelectionLabel(UISelectItems.java:234) [:2.2.2.Final]
                      at org.jboss.seam.ui.component.UISelectItems.getValue(UISelectItems.java:154) [:2.2.2.Final]
                      at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:283) [:1.2_15-20100816-SNAPSHOT]
                      at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:783) [:1.2_15-20100816-SNAPSHOT]
                      at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280) [:1.2_15-20100816-SNAPSHOT]
                      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:864) [:1.2_15-20100816-SNAPSHOT]
                      at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:281) [:3.3.3.Final]
                      at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258) [:3.3.3.Final]
                      at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200) [:3.3.3.Final]
                      at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195) [:3.3.3.Final]
                      at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120) [:3.3.3.Final]
                      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:840) [:1.2_15-20100816-SNAPSHOT]
                      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930) [:1.2_15-20100816-SNAPSHOT]
                      at javax.faces.render.Renderer.encodeChildren(Renderer.java:148) [:1.2_15-20100816-SNAPSHOT]
                      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:840) [:1.2_15-20100816-SNAPSHOT]
                      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930) [:1.2_15-20100816-SNAPSHOT]
                      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933) [:1.2_15-20100816-SNAPSHOT]
                      at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592) [:2.2.2.Final]
                      at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100) [:3.3.3.Final]
                      at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176) [:3.3.3.Final]
                      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110) [:1.2_15-20100816-SNAPSHOT]
                      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) [:1.2_15-20100816-SNAPSHOT]
                      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [:1.2_15-20100816-SNAPSHOT]
                      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266) [:1.2_15-20100816-SNAPSHOT]
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) [:2.2.2.Final]
                      at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206) [:3.3.3.Final]
                      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) [:3.3.3.Final]
                      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388) [:3.3.3.Final]
                      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515) [:3.3.3.Final]
                      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                      at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) [:2.2.2.Final]
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
                      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
                      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [:6.1.0.Final]
                      at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
                      at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
                      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
                      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
                      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
                      at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
                      at java.lang.Thread.run(Unknown Source) [:1.6.0_35]
            Caused by: javax.el.ELException: /Collaboration2.xhtml @17,73 value="#{collaboration.ontology}": org.jboss.seam.RequiredException: @In attribute requires non-null value: collaboration.em
                      at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76) [:1.1.15.B1]
                      at javax.faces.component.UIOutput.getValue(UIOutput.java:184) [:1.2_15-20100816-SNAPSHOT]
                      ... 68 more
            Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: collaboration.em
                      at org.jboss.seam.Component.getValueToInject(Component.java:2361) [:2.2.2.Final]
                      at org.jboss.seam.Component.injectAttributes(Component.java:1739) [:2.2.2.Final]
                      at org.jboss.seam.Component.inject(Component.java:1557) [:2.2.2.Final]
                      at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61) [:2.2.2.Final]
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                      at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [:2.2.2.Final]
                      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [:2.2.2.Final]
                      at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) [:2.2.2.Final]
                      at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) [:2.2.2.Final]
                      at org.domain.obaita.session.CollaborationHome_$$_javassist_seam_10.getOntology(CollaborationHome_$$_javassist_seam_10.java)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_35]
                      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_35]
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_35]
                      at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_35]
                      at javax.el.BeanELResolver.getValue(BeanELResolver.java:302) [:1.0.0.Final]
                      at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:173) [:1.2_15-20100816-SNAPSHOT]
                      at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:200) [:1.2_15-20100816-SNAPSHOT]
                      at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53) [:1.0_02.CR5]
                      at org.jboss.el.parser.AstValue.getValue(AstValue.java:67) [:1.0_02.CR5]
                      at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) [:1.0_02.CR5]
                      at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71) [:1.1.15.B1]
                      ... 69 more
            
            
            I've tried some other solutions for the @In problem, but all failed 
            
            • 3. Re: java.lang.NullPointerException when using EntityManager on Seam
              Martin Kouba Master

              First @In should be enough because of auto-create="true". And the injection point should be either @In EntityManager entityManager; or @In("entityManager") EntityManager em; -> the name of the component is "entityManager". Sorry to miss that in my first comment

              1 of 1 people found this helpful
              • 4. Re: java.lang.NullPointerException when using EntityManager on Seam
                Luan Garcia Newbie

                Thanks Martin.

                 

                Indeed, it worked, but now I have a new problem haha.

                In the CollaborationHome, here:

                 

                 

                
                @Out(required = false)
                
                
                List<Ontology> ontologyList;
                
                
                
                
                
                
                
                @Factory("ontologies")
                
                
                
                
                
                
                public void getOntologies()
                
                
                
                
                
                
                {
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                ontologyList =  (List<Ontology>) em.createQuery("from Ontology").getResultList();
                
                
                }
                
                
                
                
                
                
                I'm getting this exception:
                

                 

                GRAVE [facelets.viewhandler] Error Rendering View[/Collaboration2.xhtml]: java.lang.IllegalArgumentException: attempted to bind an @Out attribute of the wrong type to: collaboration.ontologyList
                          at org.jboss.seam.Component.outjectAttribute(Component.java:1782) [:2.2.2.Final]
                          at org.jboss.seam.Component.outjectAttributes(Component.java:1758) [:2.2.2.Final]
                          at org.jboss.seam.Component.outject(Component.java:1611) [:2.2.2.Final]
                          at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:86) [:2.2.2.Final]
                          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                          at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [:2.2.2.Final]
                          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [:2.2.2.Final]
                          at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [:2.2.2.Final]
                          at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) [:2.2.2.Final]
                          at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) [:2.2.2.Final]
                          at org.domain.obaita.session.CollaborationHome_$$_javassist_seam_15.getOntologies(CollaborationHome_$$_javassist_seam_15.java)
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_35]
                          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_35]
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.6.0_35]
                          at java.lang.reflect.Method.invoke(Unknown Source) [:1.6.0_35]
                          at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [:2.2.2.Final]
                          at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) [:2.2.2.Final]
                          at org.jboss.seam.Component.callComponentMethod(Component.java:2275) [:2.2.2.Final]
                          at org.jboss.seam.Component.getInstanceFromFactory(Component.java:2101) [:2.2.2.Final]
                          at org.jboss.seam.Component.getInstance(Component.java:2014) [:2.2.2.Final]
                          at org.jboss.seam.Component.getInstance(Component.java:1986) [:2.2.2.Final]
                          at org.jboss.seam.Component.getInstance(Component.java:1980) [:2.2.2.Final]
                          at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55) [:2.2.2.Final]
                          at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50) [:2.2.2.Final]
                          at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148) [:2.2.2.Final]
                          at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51) [:2.2.2.Final]
                          at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:173) [:1.2_15-20100816-SNAPSHOT]
                          at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:200) [:1.2_15-20100816-SNAPSHOT]
                          at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44) [:1.0_02.CR5]
                          at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) [:1.0_02.CR5]
                          at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71) [:1.1.15.B1]
                          at javax.faces.component.UISelectItems.getValue(UISelectItems.java:141) [:1.2_15-20100816-SNAPSHOT]
                          at org.jboss.seam.ui.component.UISelectItems.getValue(UISelectItems.java:161) [:2.2.2.Final]
                          at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:283) [:1.2_15-20100816-SNAPSHOT]
                          at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:783) [:1.2_15-20100816-SNAPSHOT]
                          at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280) [:1.2_15-20100816-SNAPSHOT]
                          at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:864) [:1.2_15-20100816-SNAPSHOT]
                          at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:281) [:3.3.3.Final]
                          at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258) [:3.3.3.Final]
                          at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200) [:3.3.3.Final]
                          at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195) [:3.3.3.Final]
                          at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120) [:3.3.3.Final]
                          at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:840) [:1.2_15-20100816-SNAPSHOT]
                          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930) [:1.2_15-20100816-SNAPSHOT]
                          at javax.faces.render.Renderer.encodeChildren(Renderer.java:148) [:1.2_15-20100816-SNAPSHOT]
                          at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:840) [:1.2_15-20100816-SNAPSHOT]
                          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930) [:1.2_15-20100816-SNAPSHOT]
                          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933) [:1.2_15-20100816-SNAPSHOT]
                          at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592) [:2.2.2.Final]
                          at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100) [:3.3.3.Final]
                          at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176) [:3.3.3.Final]
                          at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110) [:1.2_15-20100816-SNAPSHOT]
                          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) [:1.2_15-20100816-SNAPSHOT]
                          at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [:1.2_15-20100816-SNAPSHOT]
                          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266) [:1.2_15-20100816-SNAPSHOT]
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) [:2.2.2.Final]
                          at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                          at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                          at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                          at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                          at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206) [:3.3.3.Final]
                          at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) [:3.3.3.Final]
                          at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388) [:3.3.3.Final]
                          at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515) [:3.3.3.Final]
                          at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                          at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                          at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [:2.2.2.Final]
                          at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) [:2.2.2.Final]
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
                          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
                          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
                          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
                          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
                          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [:6.1.0.Final]
                          at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
                          at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
                          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
                          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
                          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
                          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
                          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
                          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
                          at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
                          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
                          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
                          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
                          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
                          at java.lang.Thread.run(Unknown Source) [:1.6.0_35]
                
                

                 

                Wich have no sense for me, since the return of that query is a List<Ontology> and my ontologyList is a List<Ontology>.

                Sorry for being such a noob, but Seam is a bit confusing for me :S

                • 5. Re: java.lang.NullPointerException when using EntityManager on Seam
                  Martin Kouba Master

                  I think it's a similar naming issue. Try this:

                  @Out(required = false, value="ontologies")
                  List<Ontology> ontologyList;
                   
                  @Factory("ontologies")
                  public void getOntologies() {
                  ...
                  }
                  

                  or the second type of factory method:

                  // This is not needed any more
                  // @Out(required = false, value="ontologies")
                  // List<Ontology> ontologyList;
                   
                  @Factory("ontologies")
                  public List<Ontology> getOntologies() {
                   return ...
                  }
                  
                  • 6. Re: java.lang.NullPointerException when using EntityManager on Seam
                    Luan Garcia Newbie

                    Thanks a lot man, that was the problem!

                    Problem solved