7 Replies Latest reply on Jan 29, 2002 12:15 AM by sachin

    Transaction locking problem

      I am having trouble with a transaction problem. Environment:
      JBoss2.4.4 w/Tomcat 4 (tomcat isn't being used however)
      Windows XP
      JDK 1.3.0_02 (Sun)

      I have a single CMP entity bean being stored in the Hypersonic DB. I only have one instance at this point (1 row). This bean has some business logic in it, outside of the usual get/set methods. My deployment descriptor is set so that every method has transactions set to RequiresNew.

      None of the settings in the config files have changed from default. Well, except for the custom finder in the standardjaws.xml file.

      My 'client' is a series of JUnit tests.

      Problem: Sometimes when I invoke one of the methods, I am getting a transactionrollback exception (coming from the pessimistic locking class). While this by itself wouldn't bother me so much, the trouble is that I can no longer lookup and invoke a method on the bean again without restarting JBoss. My client freezes and I get nothing in the JBoss console.

      To compound it, even when I restart JBoss, I'll get the same exception on the first method call on the bean. To fix it, I have to manually delete the bean from the hsql db, restart JBoss, then re-create the bean using my home.create(). I have, on occasion had it deleted for me by jaws/jboss(?), which is not good either. In testing this isn't so bad, but this of course wouldn't do later on.

      Any ideas? If I haven't provided enough info, please let me know!

      Thanks a bunch,

        • 1. Re: Transaction locking problem

          Just an idea:
          Try to use Requires instead of RequiresNew.


          • 2. Re: Transaction locking problem

            I don't really see how this could be happening... but are there more concurrent calls to your bean than connections to hypersonic? There are some scenarios with local transactions (ie non xa drivers) where you can run out of connections with requiresNew calls.

            If it does not appear to be a dumb mistake, is there any chance you could turn this into a testcase for the testsuite?

            • 3. Re: Transaction locking problem

              roadrunner: I've tried both varients for the transactions and no difference :-(

              davidjencks: It boggles me too. I thought it might be the database causing trouble, cause it will happen after a restart of JBoss. The very first call to the bean will cause a TransactionRollbackException saying that it is trying to remove the bean lock and it has a tx set. Yet I made no previous call to it. Somehow this 'state' is being maintained even after the server is restarted. The only way to 'fix' it is to stop the server, manually delete the row in the database, restart the server and recreate the bean. Not good.

              Also, I installed MySQL and that didn't do anything either; thinking it was hsql somehow. Unless it is the XADataSource driver. (using the JBoss one)

              I thought about the connections/calls problem too. But _sometimes_ it works... I've also noticed that a transaction will get rolled back if I let the server sit, i.e. no calls of any kind going to it.

              I'll try to isolate exactly when it is happening if I can so it can be tested. I'm also going to try to front it with a session bean (I have a reason for not, but not enough of one that I can't use a SLSB fronting the entity bean) and set the transaction at that level. Not sure if it will help, but who knows.

              Any other thoughts?


              • 4. Re: Transaction locking problem

                Hi Robert,
                Well, i too have a similar kind of problem though not exactly the same. I am unable to delete a record from db through jsp page.
                I am getting exception while i try to shutdown the server using ctrl+c. The exception is of the same kind which mentions NullPointer and then something about tx.
                I am using jsp-sessionbean-entity bean.
                It seems to be a transaction locking problem.
                However in my case the first time i try to delete a record after server boot, it is successful. But subsequent calls freeze the server.
                Did post a topic 'record deletion' but have not found replies on that.
                Will write the solution if i find one.


                • 5. Re: Transaction locking problem

                  Does Hypersonic support commit/rollback standards (I've never used it)? What about MySql (as far as I know the plain Mysql is commit/rollback unaware and u need MySql-Max breed to use commit/rollback). Anyway this is just an ideea. U should send us somehow the actual code in order to be able to better judge this one. And as knew JBoss implements pessimistic lock policy for the EJBs, so there should be no attempt from one transaction to intersect with others.

                  • 6. Re: Transaction locking problem: UPDATE

                    Ok, I have news on this issue. Quick background... I think I didn't mention it (my fault!), but my bean was looking up a datasource when it was loaded and storing it in a class variable. The reason for this was that some of the business methods used the datasource for JDBC operations.

                    Now, that was the whole problem. For whatever reason, keeping this DS was not good. The container, or the DS manager or whatever didn't like it and it conflicted with the transactions. What I did to correct it is to not store the DS in a class variable, but look it up each time I needed it, i.e. in each method invocation. Maybe not quite as fast, but it solved the problem.

                    I don't think I would really call this a bug per se, but a gotcha, as I don't know the particulars of how the transaction manager interacts with the datasource manager(?), but, there it is.

                    Thanks for the help and feedback though!

                    • 7. Re: Transaction locking problem: UPDATE

                      Hi All,
                      Well even i have solved the problem of record deletion.
                      What i did was that i got a new connection for each of the SQL queries i fired and then closed at the method end( i use bmp).
                      That solved my problem. My transaction attributes were set to Required in Session bean and Mandatory in the Entity bean with SB calling EB.
                      I had my application working on sun's j2ee server but when i ported it to jboss i had to make the above changes.
                      With this i believe i have to set the GCInterval to lesser time so as to garbage collect the connection objects.
                      Do give me inputs on this so that my code is efficient at least in this area.