Transaction management in iBATIS 3 inside an EJB container (3.1)

Is there anyone using iBATIS 3 as their persistence structure inside an EJB container? I recently started creating a new system for which I choose EJB 3.1 (the EJB version is not really relevant to this issue), as my application infrastructure and iBATIS 3 (this version is important!) As my save system. My business logic is implemented in an EJB 3.1 beans session that uses iBATIS 3 to access data. I am running on GlassFish v3)

My problem with this stack is related to transaction management. I solved the problem by writing a simple integration code, but I was a little surprised that I had to do this. So I decided to publish this to find out if others had encountered this, and if so, how they solved the problem.

My requirement for iBATIS 3 is to transparently use an EJB transaction (usually declaratively) in a bean session. iBATIS 3 provides 2 JdbcTransactionFactory and ManagedTransactionFactory transaction factories, and I found that none of them work correctly in the EJB environment (and looking at the iBATIS source, I understand why it does not work).

JdbcTransactionFactory is not suitable, since I want any calls to sqlSession.commit () or sqlSession.rollback () to be ignored. Therefore, I thought I should use ManagedTransactionFactory, as it calls any sqlSession.commit () or sqlSession.rollback () calls that need to be ignored, however this also leads to sqlSession.close () not closing the connection that iBATIS opened from DataSource in sqlSession.open () (DataSource is a DataSource object managed by the container that I provide iBATIS). This causes GlassFish to exhaust the connection pool and the application does not work.

So, I wrote a new implementation of TransactionFactory, EJBTransactionFactory, which calls sqlSession.commit () or sqlSession.rollback () to do nothing, but closes the connection when sqlSession.close () is called.

I suspect other people have come across this, how did you solve it?

+4
source share
1 answer
+2
source

Source: https://habr.com/ru/post/1307288/


All Articles