8 Replies Latest reply on Oct 23, 2006 5:47 PM by andyd

    UserModule transaction problem

    alexandru30043004

      Hi everybody.

      I want to create a portal that extends the UserProfile. I want to have more fields so I created a new table in DB and joined it with users by user_id.

      I can get the UserModule through JNDI name but my problem is that when I want to save a new user I can't make it all in one transaction. I use Hibernate for accessing my table.

      Can anyone give me an ideea please?

      Regards.


        • 1. Re: UserModule transaction problem
          soshah

          You should be able to run this operation within the scope of a transaction and have both operations work as a single unit


          You can do this programmatically kind of like this for a hint:

          UserTransaction tx = NamingContext.lookup("javax.transaction.UserTransaction");
          tx.begin();
          
          //your code here
          addMyUser
          userModule.addUser
          
          tx.commit();
          



          Even more elegant is using container-managed transaction using EJB 3.0 or something like that.


          I have personally used it with EJB 3.0 container managed transactions and it works just fine.

          Thanks
          Sohil

          • 2. Re: UserModule transaction problem
            alexandru30043004

            How can I use container-managed transaction?

            Can you give some ideas, what should I configure or what the code should be like?

            Thanks.

            • 3. Re: UserModule transaction problem
              soshah

              For using container managed transactions look at

              EJB3.0. Your business controller logic looks simple and the transaction is managed by the container within which your bean runs.


              If EJB3.0 is not part of your architecture, use programmatic transaction management like the code snippet I submitted in the earlier post

              Thanks
              Sohil

              • 4. Re: UserModule transaction problem
                alexandru30043004


                I've tried using

                UserTransaction tx = (UserTransaction) new InitialContext().lookup("javax.transaction.UserTransaction");

                but tx is null, doesn't retrieve an object. Maybe the key "javax.transaction.UserTransaction" is wrong. Can you please tell me where should I look for the right key, in what xml file?

                Thanks.

                • 5. Re: UserModule transaction problem

                  By default the transaction is suspended before the call to the portlet container. You need to flag your portlet to require a transaction in the portal object descriptor. There are examples for that in the standard descriptor examples.
                  After flagging your portlet there, you should be able to lookup the UserTransaction.... (in theory ;)

                  • 6. Re: UserModule transaction problem
                    alexandru30043004


                    I managed to find in a test case in jboss portal sources a class that retrieves the transaction like that:

                    (UserTransaction)new InitialContext().lookup("UserTransaction");

                    but when I run this code I get
                    Error org.jboss.tm.usertx.client.ServerVMClientUserTransaction
                    ErrorType java.lang.ClassCastException
                    Stacktrace ...

                    Any ideea?


                    • 7. Re: UserModule transaction problem
                      alexandru30043004


                      This is very strange because I found the class org.jboss.tm.usertx.client.ServerVMClientUserTransaction and I looked at it's signature and it implements javax.transaction.UserTransaction so by casting to javax.transaction.UserTransaction should not throw ClassCastException.

                      I'm realy lost. Can anyone help me please.

                      Thanks

                      • 8. Re: UserModule transaction problem
                        andyd

                        Take a look at this to see if it helps.
                        Andy.

                        http://wiki.jboss.org/wiki/Wiki.jsp?page=UTFactoryLookupFailed