Comments (14)
Hi Alex, can you post a log with WebLogic?
from spring.
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.
Can you see it or would you rather me upload the thing somewhere and link to it?
from spring.
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.
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.
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.
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.
Will do will let you know. Btw, does the JPetStore use JTA transaction manager?
from spring.
No. It uses Spring itself as the TX manager but it ends up using the same mybatis TX code.
from spring.
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.
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.
Thank you!
from spring.
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.
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)
- The query cache is not cleared after transaction rolls back to a savepoint HOT 3
- mapperLocations is overwritten HOT 1
- SqlSessionFactoryBean single resource, using wildcard causes a IOException HOT 4
- When Spring has multiple ApplicationContexts, it may throw BeanCreationNotAllowedException HOT 1
- Update dependency org.mybatis:mybatis to v3.5.13 on 2.1.x
- fix: change the event type that SqlSessionFactory is listening to on 2.1.x
- Drop support 1.3.x and 2.0.x
- Support processPropertyPlaceHolders option in mapper:scan and @MapperScan
- does mybatis-spring support to use customized mapper excludeFilters? HOT 1
- The logic regarding transaction rollback seems incorrect HOT 3
- The latest springboot using mybatis-spring-stater 3.0.2 throw exception "Invalid value type for attribute 'factoryBeanObjectType': java.lang.String" HOT 6
- The first query of maybatis takes longer than the second query. How to warm up in advance? HOT 1
- Switch baseline to Spring 6.1 and Spring Batch 5.1
- Support JDK 22 on CI
- why not override postProcessBeanDefinition method in ClassPathMapperScanner
- The latest springboot using mybatis-spring-stater 3.0.3-SNAPSHOT throw exception "Invalid value type for attribute 'factoryBeanObjectType': java.lang.String" HOT 5
- An idea to adapt to Spring 6.1 HOT 3
- MyBatisSystemException message is null
- Why @MapperScan scan all interface? Maybe only scan annotated with @Mapper is better? HOT 2
- mybatis-spring official docs for english responds 404 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring.