5 Replies Latest reply on Apr 6, 2008 7:27 PM by Pete Muir

    Session is null

    Robert Diaz Newbie

      Hi all,


      I was just wondering if someone could help me out with this. I'm pretty sure that I have set everything up correctly, but whenever I navigate to a certain page, it tells me that my session is null.


      Below are the relevant files.


      Any help will be most appreciated.


      Thanks,
      Robert


      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:transaction="http://jboss.com/products/seam/transaction"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                  "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                  http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                  http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                  http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                  http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                  http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                  http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                  http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                  http://jboss.com/products/seam/navigation http://jboss.com/products/seam/navigation-2.1.xsd">
          
          <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
          
          <core:manager concurrent-request-timeout="500" 
                        conversation-timeout="120000" 
                        conversation-id-parameter="cid"
                        parent-conversation-id-parameter="pid"/>
          
          <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
          
          <persistence:managed-hibernate-session name="registrationDatabase" auto-create="true"/>
          
          <transaction:hibernate-transaction session="#{registrationDatabase}"/>
      </components>
      



      Hibernate.cfg.xml


      <!DOCTYPE hibernate-configuration PUBLIC
         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      
      <hibernate-configuration>
          <session-factory name="java:/registrationDatabase">
              <property name="show_sql">false</property>
              <property name="connection.datasource">java:/testDatasource</property>
              <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
              <property name="transaction.flush_before_completion">true</property>
              <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
              mappings...
          </session-factory>
      </hibernate-configuration>
      



      This is the object that I'm using. EventT is the entity object.


      @Name("eventTList")
      public class EventTList extends HibernateEntityQuery<EventT> {
      
           private EventT eventT = new EventT();
      
           @Override
           public String getEjbql() {
                return "select eventT from EventT eventT";
           }
      
           @Override
           public Integer getMaxResults() {
                return 25;
           }
      
           public EventT getEventT() {
                return eventT;
           }
      }
      



      Here is the part of the page I'm using this in


      <h:form id-="form2">
          <rich:dataTable id="eventDataTable"
                  value="#{eventTList}" var="event">
                  <h:column>
                          <h:outputText id="eventName" value="#{event.name}" />
                  </h:column>
                  <h:column>
                          <h:inputHidden id="eventUUID" value="#{event.id}" />
                  </h:column>
          </rich:dataTable>
      </h:form>



      Here is the stack trace that I get, in case it helps at all.


      java.lang.IllegalStateException: session is null
           at org.jboss.seam.framework.HibernateEntityQuery.validate(HibernateEntityQuery.java:32)
           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:21)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
           at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
           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:166)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
           at us.gaaoc.ejb.EventTList_$$_javassist_3.validate(EventTList_$$_javassist_3.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.seam.util.Reflections.invoke(Reflections.java:21)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2084)
           at org.jboss.seam.Component.callCreateMethod(Component.java:2007)
           at org.jboss.seam.Component.newInstance(Component.java:1978)
           at org.jboss.seam.Component.getInstance(Component.java:1873)
           at org.jboss.seam.Component.getInstance(Component.java:1840)
           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:166)
           at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
           at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
           at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
           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.UIData.getValue(UIData.java:582)
           at org.ajax4jsf.component.UIDataAdaptor.getValue(UIDataAdaptor.java:1459)
           at org.ajax4jsf.component.SequenceDataAdaptor.getDataModel(SequenceDataAdaptor.java:70)
           at org.ajax4jsf.component.SequenceDataAdaptor.createDataModel(SequenceDataAdaptor.java:64)
           at org.ajax4jsf.component.UIDataAdaptor.getExtendedDataModel(UIDataAdaptor.java:592)
           at org.ajax4jsf.component.UIDataAdaptor.walk(UIDataAdaptor.java:994)
           at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:107)
           at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:92)
           at org.richfaces.renderkit.AbstractRowsRenderer.encodeChildren(AbstractRowsRenderer.java:139)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
           at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
           at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
           at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
           at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:199)
           at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:194)
           at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
           at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
           at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
           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.MultipartFilter.doFilter(MultipartFilter.java:85)
           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:141)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
           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:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           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:179)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
           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:241)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)
      

        • 1. Re: Session is null
          Khaled Yousfi Newbie

          at us.gaaoc.ejb.EventTList$$javassist3.validate(EventTList$$javassist3.java)

          I think this error occurs because you have neither an Hibernate Session nor an EntityManager defined in your component.xml


          See HibernateEntityQuery.validate documentation:
            @Override
             public void validate()
             {
                super.validate();
                if ( getSession()==null )
                {
                   throw new IllegalStateException("session is null");
                }
             }
            public Session getSession()
             {
                return getPersistenceContext();
             }



          see also: PersistenceController:
          package org.jboss.seam.framework;


          /**
          * Base class for controller objects which require a persistence
          * context object.
          *
          * @author Gavin King
          *
          * @param <T> the persistence context class (eg. Session or EntityManager)
          */
          public abstract class PersistenceController<T> extends Controller
          {
             private transient T persistenceContext;
            
             public T getPersistenceContext()
             {
                if (persistenceContext==null)
                {
                   persistenceContext = (T) getComponentInstance( getPersistenceContextName() );
                }
                return persistenceContext;
             }

             public void setPersistenceContext(T persistenceContext)
             {
                this.persistenceContext = persistenceContext;
             }

             protected abstract String getPersistenceContextName();

          }

          • 2. Re: Session is null
            Khaled Yousfi Newbie

            Sorry...
            I think this error occurs because you have neither an Hibernate Session nor an EntityManager defined in your component.xml


            See HibernateEntityQuery.validate documentation:


            @Override public void validate() { super.validate(); if ( getSession()==null ) { throw new IllegalStateException("session is null"); } } public Session getSession() { return getPersistenceContext(); }
            



            see also PersistenceController:


            package org.jboss.seam.framework; /** * Base class for controller objects which require a persistence * context object. * * @author Gavin King * * @param <T> the persistence context class (eg. Session or EntityManager) */ public abstract class PersistenceController<T> extends Controller { private transient T persistenceContext; public T getPersistenceContext() { if (persistenceContext==null) { persistenceContext = (T) getComponentInstance( getPersistenceContextName() ); } return persistenceContext; } public void setPersistenceContext(T persistenceContext) { this.persistenceContext = persistenceContext; } protected abstract String getPersistenceContextName(); }



            • 3. Re: Session is null
              Khaled Yousfi Newbie

              HibernateEntityQuery


                 @Override
                 public void validate()
                 {
                    super.validate();
                    if ( getSession()==null )
                    {
                       throw new IllegalStateException("session is null");
                    }
                 }
                 public Session getSession()
                 {
                    return getPersistenceContext();
                 }
              



              PersistenceController



              package org.jboss.seam.framework;
              
              
              /**
               * Base class for controller objects which require a persistence
               * context object.
               * 
               * @author Gavin King
               *
               * @param <T> the persistence context class (eg. Session or EntityManager)
               */
              public abstract class PersistenceController<T> extends Controller
              {
                 private transient T persistenceContext;
                 
                 public T getPersistenceContext()
                 {
                    if (persistenceContext==null)
                    {
                       persistenceContext = (T) getComponentInstance( getPersistenceContextName() );
                    }
                    return persistenceContext;
                 }
              ...


              • 4. Re: Session is null
                Robert Diaz Newbie

                Thanks for the response, but I thought that I had defined a Hibernate Session here:


                <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
                    
                <persistence:managed-hibernate-session name="registrationDatabase" auto-create="true"/>
                    
                <transaction:hibernate-transaction session="#{registrationDatabase}"/>
                
                

                • 5. Re: Session is null
                  Pete Muir Master

                  If you change your managed hibernate session's name from the default(session), you need to override it in the EntityQuery -


                  @Override
                  public String getPersistenceContextName() {
                     return "registrationDatabase";
                  }