8 Replies Latest reply on Dec 21, 2006 12:17 PM by Patrick Madden

    Hibernate SessionFactory in Seam App?

    Patrick Madden Newbie

      Hello,

      I'm in the process of porting a Tomcat w/JSP website to JBoss Seam. I have need to create a custom servlet and deploy in JBoss w/ Seam. I would like to know the proper way of accessing a the Hibernate Session Factory within the seam app

      In my old code I used the following code to access the SessionFactory

      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
      


      However, in my Stateless session beans I use the following:
      @PersistenceContext
       private EntityManager em;


      So, before I go forward I just would like to know if it is legal or valid to access the hibernate session using the Configuration method. Hope this makes sense and thank you in advance.

      PVM

        • 1. Re: Hibernate SessionFactory in Seam App?
          Gavin King Master

          What is a "custom servlet"?

          You can create Hibernate SessionFactorys anyway you like, but why not use a Seam-managed persistence context? Then you can do @In Session mySession, and get a conversation-scoped PC. Check the exmaples/hibernate2 example.

          • 2. Re: Hibernate SessionFactory in Seam App?
            Patrick Madden Newbie

            I'm sorry, I should have been more clear.

            Its a servlet that extends javax.servlet.http.HttpServlet

            When a user registers with our site we send a confirmation email to them with a return url containing some encrypted information. When they click on that link my "custom servlet" gets called. We decrypt the id parameter to decipher the UserID and Password and then notify them that they are cleared to use the site.

            So inside my HttpServlet servlet, I'd like to access the database and make sure I'm doing it in a valid or legal way. So I guess your saying in this case it would be OK to access the SessionFactory the way I described?

            Thanks again.

            PVM

            • 3. Re: Hibernate SessionFactory in Seam App?
              Gavin King Master

              Or you can wrap the SeamServletFilter around it, and get access to your Seam contexts.

              • 4. Re: Hibernate SessionFactory in Seam App?
                Patrick Madden Newbie

                Hi, I'm getting a exception as follows when trying to do as you described. I must have something else wrong unfortunately.

                javax.naming.NameNotFoundException: EntityManagerFactory not bound


                I've wrapped my servlet with SeamServletFilter as follows in web.xml

                <!-- propogate seam context to servlets (pvm) addition -->
                 <filter>
                 <filter-name>Seam Servlet Filter</filter-name>
                 <filter-class>org.jboss.seam.servlet.SeamServletFilter</filter-class>
                 </filter>
                 <filter-mapping>
                 <filter-name>Seam Servlet Filter</filter-name>
                 <url-pattern>/servlet/*</url-pattern>
                 </filter-mapping>
                <!-- end seam context to servlets -->
                


                And for my verify user servlet mapping I have the following

                 <servlet>
                 <servlet-name>VerifyUser</servlet-name>
                 <servlet-class>
                 com.clooster.web.servlet.VerifyUser
                 </servlet-class>
                 </servlet>
                
                 <servlet-mapping>
                 <servlet-name>VerifyUser</servlet-name>
                 <url-pattern>/servlet/VerifyUser</url-pattern>
                 </servlet-mapping>
                


                Inside my servlet I have an API to get the EntityManager as follows:

                 protected EntityManager getEntityManager() throws NamingException
                 {
                 EntityManagerFactory factory = (EntityManagerFactory)
                 Naming.getInitialContext().lookup("java:/EntityManagerFactory");
                
                 EntityManager em = factory.createEntityManager();
                
                 return em;
                 }
                


                Calling the above method results in the NameNotFoundException.

                One another note, once I have the above problem solved - what is the prescribed way to redirect a user to a property seam page. I'm going to attempt to do the following - will it work?

                 EntityManager em = this.getEntityManager();
                
                 ClUsers user = em.find(ClUsers.class, greeter.getName());
                
                 if (user != null)
                 {
                 // ok we have verified that this user's email address is valid
                 // and he/she is whom they say they are - set the status
                 // in the db and commit for this user.
                
                 user.setStatus((short) 1);
                
                 em.persist(user);
                
                 // now login the user
                 LoginAction loginAction = (LoginAction) Component.getInstance(LoginAction.class);
                 Contexts.getSessionContext().set("greeter", greeter);
                 loginAction.login();
                 }
                 else
                 {
                 response.getOutputStream().println(
                 "Invalid User");
                 }
                


                Or should I be using the HttpServletResponse.enodeRedirectURL API?

                Again, thank you for your great work!

                PVM

                • 5. Re: Hibernate SessionFactory in Seam App?
                  Pete Muir Master

                  I really doubt you want em.persist(user), probably em.merge(user) - persist will add a transient entity to the database not update a persistent one.

                  Can you post your persistence.xml?

                  • 6. Re: Hibernate SessionFactory in Seam App?
                    Patrick Madden Newbie

                    I see where your going with that - my persistence.xml had a different name for the factory.

                    <persistence>
                     <persistence-unit name="CloosterWeb20">
                     <provider>org.hibernate.ejb.HibernatePersistence</provider>
                     <jta-data-source>java:/CloosterWeb20Datasource</jta-data-source>
                     <properties>
                     <property name="hibernate.cache.use_query_cache" value="true"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/CloosterWeb20EntityManagerFactory"/>
                     </properties>
                     </persistence-unit>
                    </persistence>


                    So I changed my api to use the proper name and I got further along in the process. However, now I have a new exception when trying to use the Component.getInstance method. After my servlet is done verifying the user, I would like to bring the user back to either my home page or a logged in section of my site. The new exception occurs when calling this code:

                     // now login the user
                     LoginAction loginAction = (LoginAction) Component.getInstance(LoginAction.class);
                     Contexts.getSessionContext().set("greeter", greeter);
                     loginAction.login();
                    


                    The exception is:
                    11:02:31,593 ERROR [SeamExceptionFilter] uncaught exception handled by Seam
                    java.lang.ClassCastException: org.jboss.seam.intercept.Proxy$$EnhancerByCGLIB$$1
                    fc85c98
                     at com.clooster.web.servlet.VerifyUser.processRequest(VerifyUser.java:81
                    )
                     at com.clooster.web.servlet.XHttpServlet.doGet(XHttpServlet.java:37)
                     at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
                     at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:252)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilt
                    er.java:46)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.jboss.seam.servlet.SeamServletFilter.doFilter(SeamServletFilter.j
                    ava:48)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
                    lter.java:96)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                    alve.java:213)
                     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                    alve.java:178)
                     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                    yAssociationValve.java:175)
                     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                    e.java:74)
                     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                    ava:126)
                     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                    ava:105)
                     at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConne
                    ctionValve.java:156)
                     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                    ve.java:107)
                     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                    a:148)
                     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                    :869)
                     at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
                    rocessConnection(Http11BaseProtocol.java:664)
                     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
                    int.java:527)
                     at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
                    kerThread.java:112)
                     at java.lang.Thread.run(Thread.java:595)
                    11:02:31,593 ERROR [[VerifyUser]] Servlet.service() for servlet VerifyUser threw
                     exception
                    java.lang.IllegalStateException: No active event context
                     at org.jboss.seam.core.Manager.instance(Manager.java:249)
                     at org.jboss.seam.contexts.Lifecycle.flushAndDestroyContexts(Lifecycle.j
                    ava:345)
                     at org.jboss.seam.contexts.Lifecycle.endRequest(Lifecycle.java:264)
                     at org.jboss.seam.servlet.SeamServletFilter.doFilter(SeamServletFilter.j
                    ava:55)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
                    lter.java:96)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                    alve.java:213)
                     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                    alve.java:178)
                     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                    yAssociationValve.java:175)
                     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                    e.java:74)
                     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                    ava:126)
                     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                    ava:105)
                     at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConne
                    ctionValve.java:156)
                     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                    ve.java:107)
                     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                    a:148)
                     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                    :869)
                     at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
                    rocessConnection(Http11BaseProtocol.java:664)
                     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
                    int.java:527)
                     at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
                    kerThread.java:112)
                     at java.lang.Thread.run(Thread.java:595)
                    11:06:14,093 INFO [LoginAction] Entered LoginAction login
                    11:11:14,062 WARN [TransactionImpl] Transaction TransactionImpl:XidImpl[FormatI
                    d=257, GlobalId=beast/28, BranchQual=, localId=28] timed out. status=STATUS_ACTI
                    VE
                    11:11:54,203 INFO [LoginAction] Greeter is seam-test4 : [B@16a8423
                    11:11:54,218 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
                    11:11:54,218 ERROR [JDBCExceptionReporter] Transaction is not active: tx=Transac
                    tionImpl:XidImpl[FormatId=257, GlobalId=beast/28, BranchQual=, localId=28]; - ne
                    sted throwable: (javax.resource.ResourceException: Transaction is not active: tx
                    =TransactionImpl:XidImpl[FormatId=257, GlobalId=beast/28, BranchQual=, localId=2
                    8])
                    11:11:54,234 INFO [ExceptionInterceptor] no exceptions.xml file found
                    11:11:54,234 ERROR [ExceptionInterceptor] redirecting to debug page
                    javax.ejb.EJBTransactionRolledbackException: javax.persistence.PersistenceExcept
                    ion: org.hibernate.exception.GenericJDBCException: Cannot open connection
                     at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
                    
                     at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
                     at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java
                    :195)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInt
                    erceptor.java:76)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(Stateles
                    sInstanceInterceptor.java:62)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.aspects.security.AuthenticationInterceptor.invoke(Authentic
                    ationInterceptor.java:77)
                     at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3Auth
                    enticationInterceptor.java:102)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterce
                    ptor.java:47)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(Asynchrono
                    usInterceptor.java:106)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessCont
                    ainer.java:211)
                     at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalPro
                    xy.java:79)
                     at $Proxy97.login(Unknown Source)
                     at com.clooster.web.ejb.session.Login$$FastClassByCGLIB$$7b8ae7bc.invoke
                    (<generated>)
                     at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
                     at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocation
                    Context.java:45)
                     at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideIn
                    terceptor.java:69)
                     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
                    Context.java:55)
                     at org.jboss.seam.interceptors.ExceptionInterceptor.handleExceptions(Exc
                    eptionInterceptor.java:38)
                     at sun.reflect.GeneratedMethodAccessor95.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                    sorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:585)
                     at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
                     at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:16
                    9)
                     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
                    Context.java:64)
                     at org.jboss.seam.intercept.RootInterceptor.createSeamInvocationContext(
                    RootInterceptor.java:144)
                     at org.jboss.seam.intercept.RootInterceptor.invokeInContexts(RootInterce
                    ptor.java:129)
                     at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:
                    102)
                     at org.jboss.seam.intercept.ClientSideInterceptor.interceptInvocation(Cl
                    ientSideInterceptor.java:78)
                     at org.jboss.seam.intercept.ClientSideInterceptor.intercept(ClientSideIn
                    terceptor.java:47)
                     at org.jboss.seam.intercept.Proxy$$EnhancerByCGLIB$$1fc85c98.login(<gene
                    rated>)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                    java:39)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                    sorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:585)
                     at com.sun.el.parser.AstValue.invoke(AstValue.java:151)
                     at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
                    
                     at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.ja
                    va:68)
                     at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.ja
                    va:69)
                     at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
                    nListenerImpl.java:63)
                     at javax.faces.component.UICommand.broadcast(UICommand.java:106)
                     at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:9
                    4)
                     at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1
                    68)
                     at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(Lifecycl
                    eImpl.java:343)
                     at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java
                    :86)
                     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:252)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter
                    .java:32)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilt
                    er.java:46)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
                    lter.java:96)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                    icationFilterChain.java:202)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                    ilterChain.java:173)
                     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                    alve.java:213)
                     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                    alve.java:178)
                     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                    yAssociationValve.java:175)
                     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                    e.java:74)
                     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                    ava:126)
                     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                    ava:105)
                     at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConne
                    ctionValve.java:156)
                     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                    ve.java:107)
                     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                    a:148)
                     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                    :869)
                     at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
                    rocessConnection(Http11BaseProtocol.java:664)
                     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
                    int.java:527)
                     at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
                    kerThread.java:112)
                     at java.lang.Thread.run(Thread.java:595)
                    Caused by: javax.persistence.PersistenceException: org.hibernate.exception.Gener
                    icJDBCException: Cannot open connection
                     at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException
                    (AbstractEntityManagerImpl.java:647)
                     at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
                     at com.clooster.web.ejb.session.LoginAction.login(LoginAction.java:59)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                    java:39)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                    sorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:585)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:112)
                     at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationCo
                    ntextImpl.java:166)
                     at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationCo
                    ntext.java:37)
                     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
                    Context.java:55)
                     at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponen
                    t(BijectionInterceptor.java:51)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                    java:39)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                    sorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:585)
                     at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
                     at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:16
                    9)
                     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
                    Context.java:64)
                     at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(Outco
                    meInterceptor.java:23)
                     at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                    sorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:585)
                     at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
                     at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:16
                    9)
                     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
                    Context.java:64)
                     at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRun
                    ningConversation(ConversationInterceptor.java:51)
                     at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                    sorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:585)
                     at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
                     at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:16
                    9)
                     at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
                    Context.java:64)
                     at org.jboss.seam.intercept.RootInterceptor.createSeamInvocationContext(
                    RootInterceptor.java:144)
                     at org.jboss.seam.intercept.RootInterceptor.invokeInContexts(RootInterce
                    ptor.java:129)
                     at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:
                    102)
                     at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionB
                    eanInterceptor.java:49)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                    java:39)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                    sorImpl.java:25)
                     at java.lang.reflect.Method.invoke(Method.java:585)
                     at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationCo
                    ntextImpl.java:118)
                     at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3Int
                    erceptorsInterceptor.java:63)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invok
                    e(TransactionScopedEntityManagerInterceptor.java:54)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsI
                    nterceptor.java:46)
                     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
                    java:101)
                     at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                     ... 74 more
                    Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
                     at org.hibernate.exception.SQLStateConverter.handledNonSpecificException
                    (SQLStateConverter.java:103)
                     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.j
                    ava:91)
                     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp
                    er.java:43)
                     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp
                    er.java:29)
                     at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager
                    .java:420)
                     at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.
                    java:144)
                     at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatc
                    her.java:139)
                     at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1560)
                     at org.hibernate.loader.Loader.doQuery(Loader.java:661)
                     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Lo
                    ader.java:224)
                     at org.hibernate.loader.Loader.doList(Loader.java:2144)
                     at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
                     at org.hibernate.loader.Loader.list(Loader.java:2023)
                     at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
                     at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.ja
                    va:338)
                     at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java
                    :172)
                     at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
                     at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
                     at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
                     ... 121 more
                    Caused by: org.jboss.util.NestedSQLException: Transaction is not active: tx=Tran
                    sactionImpl:XidImpl[FormatId=257, GlobalId=beast/28, BranchQual=, localId=28]; -
                     nested throwable: (javax.resource.ResourceException: Transaction is not active:
                     tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=beast/28, BranchQual=, localI
                    d=28])
                     at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
                    erDataSource.java:94)
                     at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.get
                    Connection(InjectedDataSourceConnectionProvider.java:47)
                     at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager
                    .java:417)
                     ... 135 more
                    Caused by: javax.resource.ResourceException: Transaction is not active: tx=Trans
                    actionImpl:XidImpl[FormatId=257, GlobalId=beast/28, BranchQual=, localId=28]
                     at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedCo
                    nnection(TxConnectionManager.java:290)
                     at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
                    onnection(BaseConnectionManager2.java:396)
                     at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
                    nManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
                     at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
                    erDataSource.java:88)
                     ... 137 more
                    


                    Perhaps that is the correct approach - any ideas? Or should I just do something like

                    response.encodeRedirectURL("/home.seam");


                    I see that it is getting into the login action correctly but it then is having problems. Just for completeness here is my login action class (this works without problems when just going to the website and logging in)

                    @Stateless
                    @Name("login")
                    public class LoginAction implements Login
                    {
                    
                     @Logger
                     private Log log;
                    
                     @In
                     FacesMessages facesMessages;
                    
                     // if the GreeterBean does not exist in the session context, create one.
                     // variable must be named greeter as this is the @Name for the GreeterBean.
                     // Seam injects based on variable name - not class name
                     @In(create=true)
                     GreeterBean greeter;
                    
                     @PersistenceContext
                     private EntityManager em;
                    
                     @In
                     private transient Context sessionContext;
                    
                     @In
                     private transient FacesContext facesContext;
                    
                     // seam-gen method
                     @SuppressWarnings("unchecked")
                     public String login()
                     {
                     log.info("Entered LoginAction login");
                     log.info("Greeter is " + greeter);
                    
                     List<ClUsers> results = em.createQuery(
                     "from ClUsers where cloosterid=:cloosterid and password=:password")
                     .setParameter("cloosterid", greeter.getName())
                     .setParameter("password",
                     greeter.getPassword().getBytes())
                     .getResultList();
                    
                     if (results.size() == 0)
                     {
                     facesContext.addMessage(null, new FacesMessage(
                     "Invalid login"));
                    
                     return "home";
                     }
                     else
                     {
                     ClUsers user = results.get(0);
                    
                     //log.info("Logged in user = " + user.getFirstname() + " " + user.getLastname());
                     sessionContext.set("loggedIn", true);
                     sessionContext.set("user", user);
                    
                     log.info("Logged In");
                     return "main";
                     }
                     }
                    }
                    


                    Thanks again.

                    • 7. Re: Hibernate SessionFactory in Seam App?
                      Pete Muir Master

                      It's having problems instatiating the component LoginAction (probably choking on some EntityManager related operation) - but I've not got much experience in this area. If you can do a redirect like you mention then that is a cleaner approach IMO.

                      • 8. Re: Hibernate SessionFactory in Seam App?
                        Patrick Madden Newbie

                        Thanks Pete for your time and effort.

                        I ended up doing this and it seems to be working fine - I'll move on for now

                        Contexts.getSessionContext().set("loggedIn", true);
                        Contexts.getSessionContext().set("greeter", greeter);
                        Contexts.getSessionContext().set("user",user);
                        
                        response.sendRedirect(response.encodeRedirectURL("/Clooster/main.seam"));
                        


                        Page renders the proper welcome etc. So far so good.

                        Thanks again.

                        PVM