5 Replies Latest reply on Jan 22, 2009 7:12 PM by dsf sdf

    UserModule, Hibernate JTA transaction & Ajax Request

    dsf sdf Newbie

      Hi,

      i have a portlet managing user identity related issues and accessing JBossPortal UserModule.

      Everything works fine when actions are inside a "classic" http request from the portlet, ex: <h:commandButton

      But when inside an ajax request fired by clicking on a a4j:commandButton or commandLink, it seems that no hibernate session to the portal database is created.

      Does anyone know how to setup the hibernate session creation on ajax requests ?

      thanks for your help

        • 1. Re: UserModule, Hibernate JTA transaction & Ajax Request
          Andy Pemberton Newbie

          As for the portlet, in order to have a portlet share in the portal's JTA transaction, you can add the following to your jboss-portlet.xml:

          <portlet-app>
           <portlet>
           <portlet-name>YourPortlet</portlet-name>
           <transaction>
           <trans-attribute>Required</trans-attribute>
           </transaction>
           </portlet>
          </portlet-app>


          Depending on your usage scenario, there are a lot of ways to create hibernate sessions from a servlet. For example, Spring utilizes a servlet filter to bind a Hibernate Session to the thread servicing your request. Though, I'm not sure this is what you want/need to do.

          I'd be interested to know more about the kind of code you're trying to use in the AJAX servlet and the errors you're seeing.

          • 2. Re: UserModule, Hibernate JTA transaction & Ajax Request
            dsf sdf Newbie

            thanks for the help but i already included this code in the jboss-portlet.xml.

            There is no problem with "classic" http requests, hibernate sessions are created on requests to a jsf bean method issued from a h!commandButton for example.


            But the portal'jta transaction is not created when ajax requests are issued from richfaces components like a4j:commandButton.

            The missing hibernate session is the one used by portal's UserModul to access portal tables such as jbp_user for example.

            I don't think i can, or i have to create this session, it should be created by the interceptors i think.
            Maybe i should have a look to this configuration


            • 3. Re: UserModule, Hibernate JTA transaction & Ajax Request
              Andy Pemberton Newbie

              Understood. The "classic" http requests you're referring to would be PortletRequests, no? The difference being that your PortletRequests are routed through the PortletContainer's command stack where your ajax requests are handled by the servlet engine, so it would make sense that the servlet doesn't have access to the portal JTA transaction.

              Sounds exactly like: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138238#4138238

              • 4. Re: UserModule, Hibernate JTA transaction & Ajax Request
                dsf sdf Newbie

                Thanks for your help, this is exactly what i was looking for : a way to access the portal identity hibernate session.

                But actually it partially solves my problem ...

                Calling methods on UserModule inside ajaxRequest is now ok.

                BUT, as JBossPortal hibernate configuration defines lazy loaded objetcs and properties, i have lazyInitialization issues now.

                I have setup Spring to create a new transaction on each request to my managed bean.
                It solved the main problem but i now have these lazyInitialization issues.

                Maybe beacause objects are create in one hibernate session, and the lazy loading takes place in another one.

                So the best solution would be to have the session created before spring,
                but i don't know where in the portal configuration is specified the transaction management....

                • 5. Re: UserModule, Hibernate JTA transaction & Ajax Request
                  dsf sdf Newbie

                  The problem is that "classic" http requests go through a PortalServlet, then through TransactionInterceptor where is created the hibernate session/transaction.

                  Ajax request don't go the same way, these requests are directly redirected to the JSF FacesServlet.
                  So no TransactionInterception is involved and no hibernate session created ...