Thanks Marten, I worked very well. But there is a small problem, I am sure you would solve it. Actually I am passing connection as the argument to the second method where it executes some DB operation with that connection only.
So I am expecting this connection to take part in new transaction. I think it is not possible because I am not getting expected result. And in debug log I found that second transaction has different connection.
Code:
Returning cached instance of singleton bean 'org.springframework.transaction.interceptor.TransactionInterceptor#0'
Adding transactional method 'service' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '',-java.sql.SQLException
Returning cached instance of singleton bean 'transactionManager'
Creating new transaction with name [com.rest.services.DocumentServiceImpl.service]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '',-java.sql.SQLException
Acquired Connection [oracle.jdbc.driver.LogicalConnection@1194cf5] for JDBC transaction
Switching JDBC Connection [oracle.jdbc.driver.LogicalConnection@1194cf5] to manual commit
Bound value [org.springframework.jdbc.datasource.ConnectionHolder@16ac92e] for key [com.OracleDataSource@571615] to thread [http-8080-1]
Initializing transaction synchronization
Getting transaction for [com.rest.services.DocumentServiceImpl.service]
service method starts.
---call the method singalTransactionOperation
Adding transactional method 'singalTransactionOperation' with attribute: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT; '',-java.sql.SQLException
Returning cached instance of singleton bean 'transactionManager'
Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@16ac92e] for key [com.OracleDataSource@571615] bound to thread [http-8080-1]
Suspending current transaction, creating new transaction with name [com.rest.services.TransactionalHandlerImpl.singalTransactionOperation]
Clearing transaction synchronization
Removed value [org.springframework.jdbc.datasource.ConnectionHolder@16ac92e] for key [com.OracleDataSource@571615] from thread [http-8080-1]
Acquired Connection [oracle.jdbc.driver.LogicalConnection@108b095] for JDBC transaction
Switching JDBC Connection [oracle.jdbc.driver.LogicalConnection@108b095] to manual commit
Bound value [org.springframework.jdbc.datasource.ConnectionHolder@1813c12] for key [com.OracleDataSource@571615] to thread [http-8080-1]
Initializing transaction synchronization
Getting transaction for [com.rest.services.TransactionalHandlerImpl.singalTransactionOperation]
singalTransactionOperation method starts.
----did some insertion
----did something that throw SQLException
Completing transaction for [com.rest.services.TransactionalHandlerImpl.singalTransactionOperation] after exception: java.sql.SQLException: com.dao.DAOException [error=942]: ORA-00942: table or view does not exist
Applying rules to determine whether transaction should rollback on java.sql.SQLException: com.dao.DAOException [error=942]: ORA-00942: table or view does not exist
Winning rollback rule is: RollbackRuleAttribute with pattern [java.sql.SQLException]
Triggering beforeCompletion synchronization
Initiating transaction rollback
Rolling back JDBC transaction on Connection [oracle.jdbc.driver.LogicalConnection@108b095]
Triggering afterCompletion synchronization
Clearing transaction synchronization
Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1813c12] for key [com.OracleDataSource@571615] from thread [http-8080-1]
Releasing JDBC Connection [oracle.jdbc.driver.LogicalConnection@108b095] after transaction
Returning JDBC Connection to DataSource
Resuming suspended transaction after completion of inner transaction
Bound value [org.springframework.jdbc.datasource.ConnectionHolder@16ac92e] for key [com.OracleDataSource@571615] to thread [http-8080-1]
Initializing transaction synchronization
service method ends.
Completing transaction for [com.rest.services.DocumentServiceImpl.service]
Triggering beforeCommit synchronization
Triggering beforeCompletion synchronization
Initiating transaction commit
Committing JDBC transaction on Connection [oracle.jdbc.driver.LogicalConnection@1194cf5]
Triggering afterCommit synchronization
Triggering afterCompletion synchronization
Clearing transaction synchronization
Removed value [org.springframework.jdbc.datasource.ConnectionHolder@16ac92e] for key [com.OracleDataSource@571615] from thread [http-8080-1]
Releasing JDBC Connection [oracle.jdbc.driver.LogicalConnection@1194cf5] after transaction
Returning JDBC Connection to DataSource
So how would I get that connection. If I get it from the Datasource then would it be same or different. I mean the connection pooling, how would it be handled.
Thank you very much for assistance.