You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by chintan4181 <ch...@gmail.com> on 2011/04/14 03:07:14 UTC

Optimistic Lock Exception not thrown with @version

Hi,

I am trying to implement optimistic locking using JPA. I am using container
manged transaction. 

Loan entity has few other fields and one of the field is annotated with
@version. 
@Column(name = "Loan_Date_Modified")
@Version
private Timestamp Loan_Date_Modified;

In SLSB class i have followign code:
Loan loan = new Loan();
loan.setSomeProperty("newVal");

em.lock(loan, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
em.persist(loan);	

When i run multiple threads at the same time using SOAP UI to check
concurrency, it throws me Lock time out exception instead of
OptimisticLockException. I have doubt whether this is correct implementation
of optmistic lock or not.

can someone please help?

Here is excetpion details:
aused by:  org.apache.openjpa.persistence.PersistenceException: Lock request
time out period exceeded. {prepstmnt 1720673935 
UPDATE Loan 
    SET Loan_Date_Modified = ? 
    WHERE Cert_ID = ? AND Loan_Date_Modified = ? 
[params=(Timestamp) 2011-04-13 09:08:27.166, (int) 5452546, (Timestamp)
2011-04-13 09:08:24.01]} [code=1222, state=S00051]
FailedObject: com.foo.jpa.entities.Loan-5452546
	at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4827)
	at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4787)
	at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
	at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:78)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:143)
	at
org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:81)
	at
com.ibm.ws.persistence.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:47)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87)
	at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
	at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:107)
	at
org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:751)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
	... 49 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Lock request
time out period exceeded. {prepstmnt 1720673935 
UPDATE Loan 
    SET Loan_Date_Modified = ? 
    WHERE Prmary_ID = ? AND Loan_Date_Modified = ? 
[params=(Timestamp) 2011-04-13 09:08:27.166, (int) 5452546, (Timestamp)
2011-04-13 09:08:24.01]} [code=1222, state=S00051]
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:257)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:233)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$1000(LoggingConnectionDecorator.java:70)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1079)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:285)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1722)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:267)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:118)
	... 60 more
---- Begin backtrace for Nested Throwables
com.microsoft.sqlserver.jdbc.SQLServerException: Lock request time out
period exceeded.
	at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
	at
com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
	at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
	at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
	at
com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
	at
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
	at
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
	at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:308)
	at
com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecuteUpdate(WSJdbcPreparedStatement.java:1172)
	at
com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeUpdate(WSJdbcPreparedStatement.java:813)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:285)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1077)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:285)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1722)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:267)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:118)
	at
org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:81)
	at
com.ibm.ws.persistence.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:47)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87)
	at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
	at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:107)
	at
org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:751)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2139)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2037)
	at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1955)
	at
com.ibm.ws.uow.ComponentContextSynchronizationWrapper.beforeCompletion(ComponentContextSynchronizationWrapper.java:65)
	at
com.ibm.tx.jta.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:289)
	at
com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:150)
	at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2312)
	at
com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:533)
	at com.ibm.tx.jta.TransactionImpl.processCommit(TransactionImpl.java:978)
	at com.ibm.tx.jta.TransactionImpl.commit(TransactionImpl.java:913)
	at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:377)
	at com.ibm.tx.jta.TranManagerSet.commit(TranManagerSet.java:161)
	at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:927)
	at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:230)
	at
com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:570)
	at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4558)
	at com.ibm.ejs.container.WSEJBWrapper.ejbPostInvoke(WSEJBWrapper.java:253)
	at
com.ibm.ws.websvcs.server.WSInvocationListener.responseReady(WSInvocationListener.java:369)
	at
com.ibm.ws.websvcs.server.WSInvocationListener.notify(WSInvocationListener.java:89)
	at
org.apache.axis2.jaxws.server.EndpointController.responseReady(EndpointController.java:672)
	at
org.apache.axis2.jaxws.server.EndpointController.handleResponse(EndpointController.java:404)
	at
org.apache.axis2.jaxws.server.EndpointController.invoke(EndpointController.java:128)
	at
org.apache.axis2.jaxws.server.JAXWSMessageReceiver.receive(JAXWSMessageReceiver.java:159)
	at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:188)
	at
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
	at
com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.doPost(WASAxis2Servlet.java:1351)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
	at
com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
	at
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:937)
	at
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
	at
com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
	at
com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
	at
com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
	at
com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
	at
com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
	at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
	at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
	at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
	at
com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
	at
com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
	at
com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
	at
com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
	at
com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
	at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
	at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
	at
com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
	at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)

Thanks
Chintan

--
View this message in context: http://openjpa.208410.n2.nabble.com/Optimistic-Lock-Exception-not-thrown-with-version-tp6271170p6271170.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Optimistic Lock Exception not thrown with @version

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  As you have explicitly acquired a lock, a
javax.persistence.LockTimeoutException perhaps would be more appropriate
than javax.persistence.OptimisticLockException.
  In either case, OpenJPA translates database level SQL exceptions by their
error code to application-visible exceptions such as
javax.persistence.OptimisticLockException. This translation is specified in
a resource file named "sql-error-state-codes.xml". 
  Given the wide variations of SQL error codes by different database
drivers, we could only populate this translator file with some of the known
error codes and it is by no means conclusive.

  In this case, for example, SQL error code 1222 from SQLServer database is
*not* mentioned in the translator file. So OpenJPA defaulted to a generic
exception. 

  Normally, we add error codes for specific database as and when the users
encounter/report such errors.

For a quick turnaround, here is a suggestion:

1. extract the translator file "sql-error-state-codes.xml" from OpenJPA.jar
2. edit it. The edit should add the error code 1222 in <optimistic> or
<lock> clause (depending on whether the error should be translated as
OptimisticLockException or LockTimeoutException) of the appropriate database
dictionary section.
3. update OpenJPA.jar with the edited file

Please let us know if you carry out this experiment. We will then commit the
change to the original translator file.


-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/Optimistic-Lock-Exception-not-thrown-with-version-tp6271170p6720526.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Optimistic Lock Exception not thrown with @version

Posted by sonavor <jo...@worleysoftware.com>.
Hi Chintan,

Were you able to resolve what the problem you posted here?

Thanks,
John

--
View this message in context: http://openjpa.208410.n2.nabble.com/Optimistic-Lock-Exception-not-thrown-with-version-tp6271170p6718899.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.