Code Monkey home page Code Monkey logo

Comments (14)

emacarron avatar emacarron commented on June 18, 2024

Hi Alex, can you post a log with WebLogic?

from spring.

arykov avatar arykov commented on June 18, 2024

Small log snippet is bellow. Not beforeCompletion on thread 20 and afterCompletion on thread 17. Also note that Txn ID is not available in afterCompletion instead of

####<Oct 30, 2013 8:26:50 AM EDT> <Debug> <JTA2PC> <myserver> <AdminServer-whocares> <[ACTIVE] ExecuteThread: '20' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <BEA1-06DC0005216D3BF4B870> <> <1383136010485> <BEA-000000> <BEA1-06DC0005216D3BF4B870: [EJB com.xyz.app.core.async.MycNotificationQueueListenerImpl.onMessage(javax.jms.Message)]: Synchronization[org.springframework.transaction.jta.JtaAfterCompletionSynchronization@1be8756].beforeCompletion()> 
####<Oct 30, 2013 8:26:50 AM EDT> <Debug> <JTA2PC> <myserver> <AdminServer-whocares> <[ACTIVE] ExecuteThread: '20' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <BEA1-06DC0005216D3BF4B870> <> <1383136010485> <BEA-000000> <BEA1-06DC0005216D3BF4B870: [EJB com.xyz.app.core.async.MycNotificationQueueListenerImpl.onMessage(javax.jms.Message)]: Synchronization[org.springframework.transaction.jta.JtaAfterCompletionSynchronization@1be8756].beforeCompletion() END> 
...........................................
####<Oct 30, 2013 8:26:50 AM EDT> <Debug> <JTA2PC> <myserver> <AdminServer-whocares> <[ACTIVE] ExecuteThread: '17' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1383136010581> <BEA-000000> <Synchronization[org.springframework.transaction.jta.JtaAfterCompletionSynchronization@1be8756].afterCompletion(status=3)> 
####<Oct 30, 2013 8:26:50 AM EDT> <Debug> <JTA2PC> <myserver> <AdminServer-whocares> <[ACTIVE] ExecuteThread: '17' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1383136010582> <BEA-000000> <Synchronization[org.springframework.transaction.jta.JtaAfterCompletionSynchronization@1be8756].afterCompletion(status=3) END> 

from spring.

arykov avatar arykov commented on June 18, 2024

Can you see it or would you rather me upload the thing somewhere and link to it?

from spring.

emacarron avatar emacarron commented on June 18, 2024

It is OK. I can see it. I suppose you are planning in adding something like

    @Override
    public void beforeCompletion() {
      unbindResource(sessionFactory);
    }

Can you add a log.debug to that method and run the test again showing the thread ids?

Thanks in advance!

from spring.

emacarron avatar emacarron commented on June 18, 2024

BTW, I am not the expert in this area but all the code in afterCompletion relies in the commit ending status. In fact it is then when the session and the connection are released.

I you are seeing that your connections are not being closed it may happen because the call to

unbindResource(sessionFactory);

Is failing, an exception is thrown and the rest of the method is not executed. Unbind resource fails if no key is found in current TX:

    public static Object unbindResource(Object key) throws IllegalStateException {
        Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
        Object value = doUnbindResource(actualKey);
        if (value == null) {
            throw new IllegalStateException(
                    "No value for key [" + actualKey + "] bound to thread [" + Thread.currentThread().getName() + "]");
        }
        return value;
    }

It would be good if you could investigate if this is what is happening. If it is this, then we can mimic the code in DataSourceUtils, add the beforeCompletion() method and change the code in afterCompletion() to call unbindResourceIfPossible() that does not fail.

from spring.

arykov avatar arykov commented on June 18, 2024

Yes, I am thinking along the same lines - and will continue investigation. Writing a test case that will call afterCompetion in a separate thread. Hope it will reproduce the scenario without container.

from spring.

emacarron avatar emacarron commented on June 18, 2024

Hi Again Alex.

I have been gathering information about JTA and going though the Springs TX code and all confirms your point. afterCompletion can be called from a different thread so there is definitely a bug there.

I have made a change in the TX synchronization adapter but have no idea about how to unit test the change.

All other tests stil pass fine and the log in JPetStore shows the right thing:

DEBUG 2013-11-02 08:19:32,268 Creating a new SqlSession
DEBUG 2013-11-02 08:19:32,270 Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,273 JDBC Connection [org.hsqldb.jdbc.JDBCConnection@b84a4f1] will be managed by Spring
DEBUG 2013-11-02 08:19:32,274 ooo Using Connection [org.hsqldb.jdbc.JDBCConnection@b84a4f1]
DEBUG 2013-11-02 08:19:32,274 ==>  Preparing: SELECT name, nextid FROM SEQUENCE WHERE NAME = ? 
DEBUG 2013-11-02 08:19:32,275 ==> Parameters: ordernum(String)
TRACE 2013-11-02 08:19:32,276 <==    Columns: NAME, NEXTID
TRACE 2013-11-02 08:19:32,276 <==        Row: ordernum, 1000
DEBUG 2013-11-02 08:19:32,277 <==      Total: 1
DEBUG 2013-11-02 08:19:32,277 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,277 Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618] from current transaction
DEBUG 2013-11-02 08:19:32,278 ooo Using Connection [org.hsqldb.jdbc.JDBCConnection@b84a4f1]
DEBUG 2013-11-02 08:19:32,278 ==>  Preparing: UPDATE SEQUENCE SET NEXTID = ? WHERE NAME = ? 
DEBUG 2013-11-02 08:19:32,279 ==> Parameters: 1001(Integer), ordernum(String)
DEBUG 2013-11-02 08:19:32,282 <==    Updates: 1
DEBUG 2013-11-02 08:19:32,283 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,283 Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618] from current transaction
DEBUG 2013-11-02 08:19:32,284 ooo Using Connection [org.hsqldb.jdbc.JDBCConnection@b84a4f1]
DEBUG 2013-11-02 08:19:32,285 ==>  Preparing: UPDATE INVENTORY SET QTY = QTY - ? WHERE ITEMID = ? 
DEBUG 2013-11-02 08:19:32,286 ==> Parameters: 2(Integer), EST-1(String)
DEBUG 2013-11-02 08:19:32,286 <==    Updates: 1
DEBUG 2013-11-02 08:19:32,287 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,287 Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618] from current transaction
DEBUG 2013-11-02 08:19:32,290 ooo Using Connection [org.hsqldb.jdbc.JDBCConnection@b84a4f1]
DEBUG 2013-11-02 08:19:32,290 ==>  Preparing: INSERT INTO ORDERS (ORDERID, USERID, ORDERDATE, SHIPADDR1, SHIPADDR2, SHIPCITY, SHIPSTATE, SHIPZIP, SHIPCOUNTRY, BILLADDR1, BILLADDR2, BILLCITY, BILLSTATE, BILLZIP, BILLCOUNTRY, COURIER, TOTALPRICE, BILLTOFIRSTNAME, BILLTOLASTNAME, SHIPTOFIRSTNAME, SHIPTOLASTNAME, CREDITCARD, EXPRDATE, CARDTYPE, LOCALE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
DEBUG 2013-11-02 08:19:32,293 ==> Parameters: 1000(Integer), j2ee(String), 2013-11-02 08:19:23.891(Timestamp), 901 San Antonio Road(String), MS UCUP02-206(String), Palo Alto(String), CA(String), 94303(String), USA(String), 901 San Antonio Road(String), MS UCUP02-206(String), Palo Alto(String), CA(String), 94303(String), USA(String), UPS(String), 33.00(BigDecimal), ABC(String), XYX(String), ABC(String), XYX(String), 999 9999 9999 9999(String), 12/03(String), Visa(String), CA(String)
DEBUG 2013-11-02 08:19:32,294 <==    Updates: 1
DEBUG 2013-11-02 08:19:32,294 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,295 Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618] from current transaction
DEBUG 2013-11-02 08:19:32,295 ooo Using Connection [org.hsqldb.jdbc.JDBCConnection@b84a4f1]
DEBUG 2013-11-02 08:19:32,295 ==>  Preparing: INSERT INTO ORDERSTATUS (ORDERID, LINENUM, TIMESTAMP, STATUS) VALUES (?, ?, ?, ?) 
DEBUG 2013-11-02 08:19:32,296 ==> Parameters: 1000(Integer), 1000(Integer), 2013-11-02 08:19:23.891(Timestamp), P(String)
DEBUG 2013-11-02 08:19:32,297 <==    Updates: 1
DEBUG 2013-11-02 08:19:32,297 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,298 Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618] from current transaction
DEBUG 2013-11-02 08:19:32,299 ooo Using Connection [org.hsqldb.jdbc.JDBCConnection@b84a4f1]
DEBUG 2013-11-02 08:19:32,299 ==>  Preparing: INSERT INTO LINEITEM (ORDERID, LINENUM, ITEMID, QUANTITY, UNITPRICE) VALUES (?, ?, ?, ?, ?) 
DEBUG 2013-11-02 08:19:32,300 ==> Parameters: 1000(Integer), 1(Integer), EST-1(String), 2(Integer), 16.50(BigDecimal)
DEBUG 2013-11-02 08:19:32,301 <==    Updates: 1
DEBUG 2013-11-02 08:19:32,301 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,301 Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,302 Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]
DEBUG 2013-11-02 08:19:32,302 Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fa3e618]

Can you please test the change?

from spring.

arykov avatar arykov commented on June 18, 2024

Will do will let you know. Btw, does the JPetStore use JTA transaction manager?

from spring.

emacarron avatar emacarron commented on June 18, 2024

No. It uses Spring itself as the TX manager but it ends up using the same mybatis TX code.

from spring.

emacarron avatar emacarron commented on June 18, 2024

I have been playing with Atomikos properties to see if I can get Weblogic's behaviour by chance but I could not. In fact when changing properties I see no difference in behavior at all.

I am afraid I will give up. Anyway it is good to have a real JTA test case in the project.

So please Alex, give the snapshot a try. If you see no error in your project I think we can close the issue.

The snapshot is available here: https://code.google.com/p/mybatis/downloads/list?can=3&q=Product%3DSpring

And thanks in advance!

from spring.

arykov avatar arykov commented on June 18, 2024

App with snapshot is going into test environment for a couple days starting today. Will let you know. Once I have a bit more time will continue attempts to reproduce in JUnit.

from spring.

emacarron avatar emacarron commented on June 18, 2024

Thank you!

from spring.

dguggi avatar dguggi commented on June 18, 2024

FYI:

We also have an issue using mybatis-spring-1.2.1/1.2.0 that relates to this bug.

We use a custom TransactionSynchronization with afterCompletion method using Glassfish-JTA. We also run into IllegalStateExceptions using mybatis-spring-1.2.1/1.2.0.

mybatis-spring-1.2.2 resolves our issue.

when do you plan to release 1.2.2 :)

ty,
daniel

from spring.

emacarron avatar emacarron commented on June 18, 2024

Soon Daniel, soon :)

But you both will help us a lot using the snapshot in your systems and providing feedback.

Probably the final version will have no more changes.

from spring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.