1 2 3 Previous Next 36 Replies Latest reply on Nov 29, 2013 10:26 AM by tomjenkinson

    JBoss Transaction not rolling back

    memyself141

      Hi All,

       

      I am really stuck on a weird problem since a week. I'd be really grateful if anybody can share insights on this one :

       

      I have a 3rd party tool (EJB 2.0) deployed on JBoss 5.1.  I have to use these EJBs using the client code somewhat like this :

       

      UserTransaction ut = (UserTransaction)InitialContext.lookup("UserTransaction");

      ut.begin();

      callSomeMethodOnEJB1();

      callSomeMethodonEJB2();

      if(errorFound)

      {

           callFinalMethod();

           ut.rollback();

      }

       

      The above code works fine when written in a POJO client (inside a plain main() method). The transaction (the changes made by MethodOnEJB1 and 2) gets rolled back in case of 'erroeFound' being true.

       

      However, the same code does not rollback the transaction when I run it from my client web-app which is also deployed on JBoss 5.1 (local server on my machine, not the same as the remote server where EJBs are deployed).

       

      The difference that I found out between the 2 codes is that

      1. in POJO client, the InitialContext.lookup("UserTransaction") returns an instance of ClientUserTransaction while

      2. in JBoss client, the InitialContext.lookup("UserTransaction"); returns an instance of ServerVMClientUserTransaction.

       

      Is there something that I can do so that the transaction gets rolled back in the JBoss client too.... Any help would be great...

      Please let me know if you need anymore info on this.....

       

      Thanks in advance.

       

      Message was edited by: AAYUSH SINGHAL

        • 1. Re: JBoss Transaction not rolling back
          mmusgrov

          You could try calling getStatus on the user transaction (ut). If it returns STATUS_NO_TRANSACTION then start the transaction running as in ut.begin().

          • 2. Re: JBoss Transaction not rolling back
            memyself141

            Thanks for the response Michael.

             

            But I have done ut.begin() already (although it's not in my pseudo-code above . Updated it now). The ut.getStatus returns 0 (STATUS_ACTIVE). So that is all right.

             

            The problem is that the transaction is rolling back fine from a POJO client (from inside a main() method) but doesn't when I write it in my client web-app which is deployed on a local JBoss server (other than the one where the EJBs are deoployed).

            What could I be doing wrong???

             

            Can you please help me with this... I am really stuck on this one since a week and can't get a way to do it right....

            • 3. Re: JBoss Transaction not rolling back
              tomjenkinson

              It looks like it might work, you might get a better answer in the JBoss AS5 forum. What transactional attributes are the EJBs marked up with, maybe @REQUIRES_NEW, though as it works in your pojo I guess @REQUIRED?

              • 4. Re: JBoss Transaction not rolling back
                mmusgrov

                It sounds like you are saying that the web app and the ejbs are running in different servers. Have you configured the servers to use distributed (JTS) transactions.

                1 of 1 people found this helpful
                • 5. Re: JBoss Transaction not rolling back
                  mmusgrov

                  The difference that I found out between the 2 codes is that

                  1. in POJO client, the InitialContext.lookup("UserTransaction") returns an instance of ClientUserTransaction while

                  2. in JBoss client, the InitialContext.lookup("UserTransaction"); returns an instance of ServerVMClientUserTransaction.

                   

                   

                   

                  In 1 you will be getting a proxy for starting transactions on the server where your EJBs are running whereas I think in 2 you are getting a transaction running on the app server running your web app but that transaction (context) doesn't get propagated to the other server that hosts your EJBs. What happens if you co-locate the web app and the EJBs

                  1 of 1 people found this helpful
                  • 6. Re: JBoss Transaction not rolling back
                    memyself141

                    Thanks Tom. It is indeed @REQUIRED.

                    • 7. Re: JBoss Transaction not rolling back
                      memyself141

                      Thanks Michael... yes, the web-app and the ejbs are on separate JBoss servers. I cannot put my web-app on the EJBs server... I do not have the rights to do that... The EJBs are actually a 3rd party vendor's tool exposed as stateless EJBs.

                       

                       

                      I was looking through Distributed Transaction services but couldn't get much of it. Could you point me to some good source where I can read about it. Again, I can only try turning it ON on my web-app server only.... But I will try to do it..... will update you

                       

                       

                      About getting ServerVMClientUserTransaction, that is what my intuition is... why am i getting this instance from my web-app server and not the EJBs server..... I am looking up the JNDI using the InitialContext being point to the remote EJBs server....  The JBoss document does say that ServerVMClientUserTransaction is returned for the server where the JBoss is running.... but what if the client too is on JBoss like in my case....

                      • 8. Re: JBoss Transaction not rolling back
                        tomjenkinson

                        You may find this article useful: Transaction Propagation with JBoss

                        • 9. Re: JBoss Transaction not rolling back
                          mmusgrov

                           

                          I was looking through Distributed Transaction services but couldn't get much of it. Could you point me to some good source where I can read about it. Again, I can only try turning it ON on my web-app server only.... But I will try to do it..... will update you

                           

                          You would have to enable JTS on both servers for the transaction to propagate successfully. After rereading your post you say you are specifying the server hosting the EJBs in your JNDI lookup for the UserTransaction but instead you are getting an instance of ServerVMClientUserTransaction which I would not have expected. Are you sure the JNDI properties refer to the other host. If so I would need to have a play on my laptop, would it be possible for you provide a cut down version of your app.

                          • 10. Re: JBoss Transaction not rolling back
                            memyself141

                            Thank you so much Tom... I've been going through the same post actually... It is really helpful... also it clears out that I will definitely need the Distributed Transactions as apart from just invoking the EJBs, I may (in near future) need to execute a couple of updates on the datasource using JDBC queries....

                             

                            Thanks Michael... That's really kind of you to try it out yourself.... I've been reading about JBoss Distributed Transacations to get done with this...

                            About getting the ServerVMClientUserTransaction, that is what is confusing me the most and might be the core of the problem that I am facing..... The JNDI properties do refer to the other host... I used the same code on a POJO client and it works fine....

                            But I don't know how can I give you a cut-down version of my web-app.... I'll again give you a description... I have the EJB 2.0 with CMT deployed on server JBoss 5.1. Then I have a simple client web-app (servlet based) deployed on my local JBoss 5.1 that creates an InitialContext setting the environment properties for remote server. Then I lookup the JNDI ("UserTransaction") and the object returned is of type ServerVMClientUserTransaction.... This instance of UserTransaction does not participate in the Transaction... I can probably give you the client web-app servlet code asap but I wouldn't be able to give you the EJBs with CMT (It's a 3rd party tool) ... Will that be ok with you??

                             

                            Thanks once again everyone for all your help... I can't tell you guys how much it means when you guys help us out in troubles like these....

                            • 11. Re: JBoss Transaction not rolling back
                              memyself141

                              Hello Michael,

                               

                              This is the client code that I run in my servlet to access the remnote EJBs.... If you could try it out on your machine, and check if you too get the ServerVMClientUserTransaction, it'd be really great.....Please let me know if you need anything more from my configurations....

                               

                              public class TestClient {

                                private static AppCallbackHandler callbackHandler;

                               

                                static String server_ip = "172.172.172.172";

                                static int server_port = 54014;

                                static String eca_user = "username";

                                static String eca_pwd = "password";

                               

                               

                                public static void main(String[] args) throws Exception {

                               

                               

                                Context ctx = new InitialContext(createContextEnvironment());

                               

                                Object ejbObject = ctx.lookup("Convergys/ECA/Customer");

                                System.out.println("EBJ looked up");

                               

                                UserTransaction ut = (UserTransaction)ctx.lookup("UserTransaction");

                               

                                System.out.println(ut.getClass().getName());

                                ut.begin();

                               

                                AccountSessionHome accHome = (AccountSessionHome) ctx.lookup

                               

                               

                              ("Convergys/ECA/Account");

                                AccountSession accSession = accHome.create();

                                accSession.makeAccountBillable_1(new AccountPK(Null.INT, "123456789"));

                                System.out.println("ECA executed successfully");

                                ut.rollback();

                               

                               

                                }

                               

                               

                                private static Hashtable<String, String> createContextEnvironment() {

                                Hashtable<String, String> env = new Hashtable<String, String>();

                                env.put(Context.INITIAL_CONTEXT_FACTORY,

                                "org.jboss.naming.NamingContextFactory");

                                env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                                env.put(Context.PROVIDER_URL, server_ip + ":" + server_port);

                                env.put(Context.SECURITY_PRINCIPAL, eca_user);

                                env.put(Context.SECURITY_CREDENTIALS, eca_pwd);

                                return env;

                                }

                               

                               

                              }

                               

                               

                              This is the code in the POJO client that is running fine. The UT is rolling back.... I copy the same code in a web-app's servlet's doGet() method and it doesn't participate in the transaction. The classname displayed for UserTransaction is ServerVMClientUserTransaction.

                              • 12. Re: JBoss Transaction not rolling back
                                memyself141

                                If you could give me your e-mail id, I can email you the WAR from my sample web-app.... I guess that would be easier to see the bigger picture as I am also loggin-in to the EJB server using AppCallbackHandler..

                                • 13. Re: JBoss Transaction not rolling back
                                  memyself141

                                  ok. I have understood how to configure my client-side JBoss  to run JTS. I can try to do the same for my server-side JBoss too... (will get the permissions). But one small other thing..... Do I need my client-side code to be inside an EJB for Distributed Transactions to work?? Right now it is plain servlet code (that is being in turn called by a web-service but that doesn't matter. It is not in an EJB)....

                                  • 14. Re: JBoss Transaction not rolling back
                                    tomjenkinson

                                    Hi Aayush,


                                    I would say not, you can use BMT from the servlet.

                                     

                                    Tom

                                    1 2 3 Previous Next