Commit failed while step execution data was already updated - java

I am getting Commit failed while step execution data was already updated error when spring batch try to commit the records. Any help would be greatly appreciated.
I am using HIbernate JPA .
It is working for lesser number of records. Throwing error when the record count is high.
Stack Trace:
2016-01-20 08:49:45 INFO TaskletStep:359 - Commit failed while step execution data was already updated. Reverting to old version.
2016-01-20 08:49:45 ERROR TaskletStep:370 - Rolling back with transaction in unknown state
2016-01-20 08:49:45 ERROR AbstractStep:225 - Encountered an error executing step uploadFiles in job fileUploadJob
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:524)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)

I had same error "Commit failed while step execution data was already updated. Reverting to old version" and I solved it by using " #Transactional(propagation = Propagation.REQUIRES_NEW)" annotation above the method where the records were committed.

Related

Getting XAException while committing the transaction, J2CA0027E - The method 'xa_end' has failed with errorCode '106' & '-4''

I've one application in which I'm trying to process a file which contains 500k transactions, the processing of file completes in 3 minutes and the timeout is set to 15 minutes, still getting timeout exception during commit.
Getting Below Exception in Websphere System Logs while committing the transaction from my code in spring, due to which all the transactions are rolledback;
XATransaction E J2CA0027E: An exception occurred while invoking end on an XA Resource Adapter from DataSource JMS$FundtechQConFactory$JMSManagedConnection#75, within transaction ID {​​​XidImpl: formatId(57415344), gtrid_length(36), bqual_length(54),
data(0000017bdaabecde0000000b6a6fc584d5dba62aea917f1902693232b82dd8a4ff309f370000017bdaabecde0000000b6a6fc584d5dba62aea917f1902693232b82dd8a4ff309f37000000010000000000000000000000000097)}​​​ : javax.transaction.xa.XAException: The method 'xa_end' has failed with errorCode '106'.
at com.ibm.mq.jmqi.JmqiXAResource.end(JmqiXAResource.java:559)
at com.ibm.ejs.jms.JMSManagedSession$JMSXAResource.end(JMSManagedSession.java:1410)
at com.ibm.ejs.j2c.XATransactionWrapper.end(XATransactionWrapper.java:623)
at com.ibm.ws.Transaction.JTA.JTAResourceBase.end(JTAResourceBase.java:254)
at com.ibm.tx.jta.impl.RegisteredResources.sendEnd(RegisteredResources.java:1154)
at com.ibm.tx.jta.impl.RegisteredResources.distributeEnd(RegisteredResources.java:1130)
at com.ibm.tx.jta.impl.TransactionImpl.distributeEnd(TransactionImpl.java:1748)
at com.ibm.tx.jta.impl.TransactionImpl.prepareResources(TransactionImpl.java:1478)
at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:630)
at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1040)
at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:974)
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439)
at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:191)
at com.ibm.ws.tx.jta.UserTransactionImpl.commit(UserTransactionImpl.java:307)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1035)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:743)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)
XATransaction E J2CA0027E: An exception occurred while invoking rollback on an XA Resource Adapter from DataSource JMS$FundtechQConFactory$JMSManagedConnection#206, within transaction ID {​​​XidImpl: formatId(57415344), gtrid_length(36), bqual_length(54),
data(0000017bdaabecde0000000b6a6fc584d5dba62aea917f1902693232b82dd8a4ff309f370000017bdaabecde0000000b6a6fc584d5dba62aea917f1902693232b82dd8a4ff309f37000000010000000000000000000000000003)}​​​ : javax.transaction.xa.XAException: The method 'xa_rollback' has failed with errorCode '-4'.
at com.ibm.mq.jmqi.JmqiXAResource.rollback(JmqiXAResource.java:874)
at com.ibm.ejs.jms.JMSManagedSession$JMSXAResource.rollback(JMSManagedSession.java:1201)
at com.ibm.ejs.j2c.XATransactionWrapper.rollback(XATransactionWrapper.java:1328)
at com.ibm.tx.jta.impl.JTAXAResourceImpl.rollback(JTAXAResourceImpl.java:381)
at com.ibm.tx.jta.impl.RegisteredResources.deliverOutcome(RegisteredResources.java:1718)
at com.ibm.tx.jta.impl.RegisteredResources.distributeOutcome(RegisteredResources.java:2004)
at com.ibm.tx.jta.impl.RegisteredResources.distributeRollback(RegisteredResources.java:2657)
at com.ibm.tx.jta.impl.TransactionImpl.internalRollback(TransactionImpl.java:1973)
at com.ibm.tx.jta.impl.TransactionImpl.internalRollback(TransactionImpl.java:1936)
at com.ibm.tx.jta.impl.TransactionImpl.coreStage2CommitProcessing(TransactionImpl.java:1156)
at com.ibm.tx.jta.impl.TransactionImpl.stage2CommitProcessing(TransactionImpl.java:1183)
at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1044)
at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:974)
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439)
at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:191)
at com.ibm.ws.tx.jta.UserTransactionImpl.commit(UserTransactionImpl.java:307)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1035)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:743)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)
Error code 106 that you get on xa.end is XA_RBTIMEOUT.
This means that the resource manager has rolled back the transaction due to exceeding a timeout.
Error code -4 that you get on xa.commit is XAER_NOTA.
This means that the transaction xid isn't valid anymore, which makes sense given the previous error - because transaction branch was already rolled back due to the timeout.
It is important to be aware that transaction timeouts can be set at various levels. WebSphere Application Server has a global transaction lifetime timeout. Various resource providers will often have their own timeout settings (I'd recommend checking if MQ does) which can cause them to time out their transaction branches prior to the overall transaction. Applications can specify a transaction timeout on UserTransaction, although it appears in this case you are going through Spring, which might be specifying that value, so also look into Springs settings for transaction timeout.

Transaction is ended due to timeout due to updating same table using two Message Drive Beans

I am using two Message Drive Beans (MDB), to update same table. I am using EJB 3.0 and using transaction type as
#TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
some times one of the methods are getting error like "Transaction is ended due to timeout" and MDB is getting deactivated. Hence , I have to restart the server.
Can I use any other type of transaction attribute #TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) to avoid the timeout error ?
Here is my stacktrace.
[:] CWWMQ0007W: The message endpoint Rsme#RsmeEJB.jar#GemsInqMDB has been paused by the system. Message delivery failed to the endpoint more than 0 times. The last attempted delivery failed with the following error: javax.ejb.EJBTransactionRolledbackException: Transaction rolled back; nested exception is: javax.transaction.TransactionRolledbackException: Transaction is ended due to timeout
javax.transaction.TransactionRolledbackException: Transaction is ended due to timeout
at com.ibm.tx.jta.impl.EmbeddableTranManagerImpl.completeTxTimeout(EmbeddableTranManagerImpl.java:62)
at com.ibm.tx.jta.impl.EmbeddableTranManagerSet.completeTxTimeout(EmbeddableTranManagerSet.java:85)
at com.ibm.ejs.csi.TransactionControlImpl.completeTxTimeout(TransactionControlImpl.java:1347)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:242)
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:579)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4843)
at com.maybank.meaa.local.EJSLocal0SLMeaaEntityBean_877f3cd5.insertPD003Result(EJSLocal0SLMeaaEntityBean_877f3cd5.java)
at com.maybank.meaa.mdbs.GemsInqMDB.onMessage(GemsInqMDB.java:75)
at com.ibm.ejs.container.MessageEndpointHandler.invokeMdbMethod(MessageEndpointHandler.java:1163)
at com.ibm.ejs.container.MessageEndpointHandler.invoke(MessageEndpointHandler.java:842)
at $Proxy27.onMessage(Unknown Source)
at com.ibm.mq.connector.inbound.MessageEndpointWrapper.onMessage(MessageEndpointWrapper.java:131)
at com.ibm.mq.jms.MQSession$FacadeMessageListener.onMessage(MQSession.java:147)
at com.ibm.msg.client.jms.internal.JmsSessionImpl.run(JmsSessionImpl.java:2665)
at com.ibm.mq.jms.MQSession.run(MQSession.java:862)
at com.ibm.mq.connector.inbound.WorkImpl.run(WorkImpl.java:279)
at com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:608)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)
javax.ejb.EJBTransactionRolledbackException: Transaction rolled back; nested exception is: javax.transaction.TransactionRolledbackException: Transaction is ended due to timeout
Caused by: javax.transaction.TransactionRolledbackException: Transaction is ended due to timeout
at com.ibm.tx.jta.impl.EmbeddableTranManagerImpl.completeTxTimeout(EmbeddableTranManagerImpl.java:62)
at com.ibm.tx.jta.impl.EmbeddableTranManagerSet.completeTxTimeout(EmbeddableTranManagerSet.java:85)
at com.ibm.ejs.csi.TransactionControlImpl.completeTxTimeout(TransactionControlImpl.java:1347)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:242)
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:579)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4843)
at com.maybank.meaa.local.EJSLocal0SLMeaaEntityBean_877f3cd5.insertPD003Result(EJSLocal0SLMeaaEntityBean_877f3cd5.java)
at com.maybank.meaa.mdbs.GemsInqMDB.onMessage(GemsInqMDB.java:75)
at com.ibm.ejs.container.MessageEndpointHandler.invokeMdbMethod(MessageEndpointHandler.java:1163)
at com.ibm.ejs.container.MessageEndpointHandler.invoke(MessageEndpointHandler.java:842)
at $Proxy27.onMessage(Unknown Source)
at com.ibm.mq.connector.inbound.MessageEndpointWrapper.onMessage(MessageEndpointWrapper.java:131)
at com.ibm.mq.jms.MQSession$FacadeMessageListener.onMessage(MQSession.java:147)
at com.ibm.msg.client.jms.internal.JmsSessionImpl.run(JmsSessionImpl.java:2665)
at com.ibm.mq.jms.MQSession.run(MQSession.java:862)
at com.ibm.mq.connector.inbound.WorkImpl.run(WorkImpl.java:279)
at com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:608)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)
.
Create two different tables with the same structure to avoid the deadlock instead of using same table for two MDB
This error can be caused by normally 2 things
1- EJB Timeout
2- Datasource Timeout
You can configurate both to a greater value.
1 - WebSphere Application servers > <> container properties > Transaction service
Total transaction lifetime timeout - this will be the default value for EJB without this property
Maximum transaction timeout - this wil be the max value for any transaction managed by WAS
2 - Data sources > <> > Connection pools
Connection timeout
Unused timeout
Normally, the option 1 fix the problem.

Ejb Finder(ejb-ql) Transaction TimesOut

We have been facing an issue, where a simple ejb-ql query runs out of transaction time, if same(WL generated SQL version of ejb-ql) is run from SQL command prompt, it takes very less time than the configured JTA time(execute less than 5% time of JTA).
Erros: Few time the error thrown is:
javax.ejb.FinderException: Exception in 'finderMethodName' while using result set: 'weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl#9c18f'
java.sql.SQLException: Unexpected exception while enlisting XAConnection java.sql.SQLException: Transaction rolled back: Transaction timed out after 301 seconds
Note - JTA is configured to 300 seconds
Most of the time the error thrown is:
javax.ejb.FinderException: Exception in 'finderMethodName' while using result set: 'weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl#a5af'
java.sql.SQLException: Result set already closed
You should increase the timeout in the container.
Service Configurations -> Other Services
Click JTA Configuration(Under Other Services)
Then you will see the Timeout Seconds on the top of the page.

Spring Batch Exception in Chunk

I have a spring batch job which has multiple steps.
Step 1 : Loads 10 records from the database. (Tasklet does that job)
Step 2: Chunk Oriented processing in configured here using ItemReader,ItemProcessor,ItemWriter implementations with commit -interval =1
Now as I understand , for every record this would happen
Begin Transaction ( Read - Process - Write ) Commit Tx
My problem is imagine it processed six records and now with the 7th Record it got an exception in the ItemProcessor Implementation, It tries to rollback but not able to rollback due to transaction in unknown state
Even if it is not able to rollback tx for 7th record it does not processes 8th,9th,10th record at all and job is STOPPED.
Note: ItemProcessor implementation is calling services (#Service annotated) which are marked as transactional using #Transactional(readOnly=false) annotation.
Please suggest the solution.
ItemProcessor Code Below
public Long process(LoanApplication loanApplication)throws Exception {
Long createLoan = null;
LoanStatus loanStatus = null;
StaffUser user = staffUserService.getStaffUserByName(Constants.AUTO_USER);
String notes = null;
try{
try{
loanValidationService.validate(loanApplication);
loanStatus=LoanStatus.U;
}catch(LoanValidationException e){
loanStatus=LoanStatus.UC;
notes=e.getMessage();
}
dataLoadLoanManagementService.setText(notes);
createLoan = dataLoadLoanManagementService.createLoan(loanApplication, user,loanStatus);
}catch(Exception le){
logger.error("Error creating the loan application ; Parent Application Ref : "
+ loanApplication
+ " with status as " +(loanStatus!=null ?loanStatus.getStatus():loanStatus)
+"\n"
+" School Ref :"
+ loanApplication.getSchoolRef()
+"\n"
+" Client Details :"
+loanApplication.getClientDetails()
+ "Error Details: " + ExceptionUtils.getStackTrace(le));
}
return createLoan;
}
Even with Skippable Exception Classes configured this does not work.
To explain bit more i get Persistence Exception in Item Processor and i catch it , therefore Spring batch executes the writer but after writer execution i get the exception below
INFO 06-21 11:38:00 Commit failed while step execution data was already updated. Reverting to old version. (TaskletStep.java:342)
ERROR 06-21 11:38:00 Rolling back with transaction in unknown state (TaskletStep.java:351)
ERROR 06-21 11:38:00 Encountered an error executing the step (AbstractStep.java:212)
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
For both of your questions, skipping the exception occured during the prosessor phase will solve your problems.
This may be configured by skippable-exception-classes element if you know the root cause of the exception. For example, if you get a divide by zero exception during the processor phase and do want to neglect it, a sample configuration might be:
<chunk reader="reader" processor="processor" writer="writer"
commit-interval="1" >
<skippable-exception-classes>
<include class="java.lang.ArithmeticException" />
</skippable-exception-classes>
</chunk>
Since the given exception class and its subclasses will be skipped, you may even try java.lang.Exception
check transaction propagation option at loanValidationService.validate
Guess from "Transaction marked as rollbackOnly", "Commit failed while step execution data was already updated"
Current transaction was rollbacked and parent Transaction should be commit but transaction already over.
if chunk's transaction is same at LoanValidationService.validate
change propagation option to REQUIRES_NEW
following article may help to understand metadata's transaction.
http://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/
class LoanValidationServiceImpl implements LoanValidationService {
#Trasnactional(propagation=REQUIRES_NEW, rollbackFor=Exception.class)
validate(LoanApplication loanApplication) {
// business logic
}
}

could not get database metadata java.sql.SQLException:

I am using hibernate sharedFactory for database updation.
When am trying to do one updation am getting the following errors on log:
2011-09-01 16:17:50,406 ERROR (org.hibernate.tool.hbm2ddl.SchemaUpdate:134:execute) - could not get database metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!
2011-09-01 16:32:05,734 ERROR (org.hibernate.tool.hbm2ddl.SchemaUpdate:165:execute) - could not complete schema update
java.sql.SQLException: Connections could not be acquired from the underlying database!
And the exception is exactly throwing on this line of code..
sessionFactoryShard = shardedConfig.buildShardedSessionFactory();
Can anyone tell why this error occurs?

Categories

Resources