openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmchale <fmch...@cisco.com>
Subject OptimisticLockException confusion.
Date Thu, 15 May 2008 00:19:29 GMT

Hi,

I am having trouble catching the OptimisticLockException that is being
thrown when I have concurrent users trying to update the same entity. 
Basically I want to be able to do is to send the one user to another page in
my app when this exception is thrown, but for some reason my attempts to
catch it are not working. I apologize if its something minor, im kinda of
new to java ee. I thought by catching the openjpa OptimisticLockException
and throwing the javax.persistence.OptimisticLockException I could achieve
the desired behaviour in the web app.  But it seems I cannot catch the
openjpa Exception.

Thanks for any help. 


Entity with @version annotation
@Entity
@Table(name="mt_interns")
@DiscriminatorValue("CI")
public class ChoiceIntern extends Intern implements Serializable {
	private static final long serialVersionUID = 1L;

	@Column(name="has_position")
	private boolean hasPosition;
	
	@OneToMany(cascade = ALL,fetch=EAGER)
	@JoinTable(name = "MT_INTERN_CHOICES", joinColumns = { @JoinColumn(name =
"INTERN_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHOICE_ID") })
	private List<Choice> choices;
	
	@OneToMany(cascade = ALL,fetch=EAGER)
	@JoinTable(name = "MT_INTERN_SKILLS", joinColumns = { @JoinColumn(name =
"INTERN_ID") }, inverseJoinColumns = { @JoinColumn(name = "SKILL_ID") })
	private List<InternSkill> skills;
......

Stateless Session Bean
...
				Match match = new Match(manager, intern, request, percentage);

				intern.setHasPosition(true);
				numberOfInterns = numberOfInterns + 1;
				request.setNumberOfInternsSelected(numberOfInterns);

				emMatchMaker.merge(intern);
				emMatchMaker.persist(match);
				emMatchMaker.merge(request);
		
				insertedInterns.add(intern);
			} catch (OptimisticException oe) {
				System.out.println("I caught the inner locking exception!");
				
				throw new javax.persistence.OptimisticLockException(oe);
			}
...

Output
7:03:26,296 WARN  [Transaction] Unexpected exception from beforeCompletion;
transaction will roll back
<openjpa-1.0.1-r420667:592145 nonfatal store error>
org.apache.openjpa.persistence.OptimisticLockException: Optimistic locking
errors were detected when flushing to the data store.  The following objects
may have been concurrently modified in another transaction:
[englrn.matchmaker.model.Request-265,
englrn.matchmaker.model.ChoiceIntern-951]
	at
org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2104)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1954)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
	at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
	at
org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:245)
	at
org.apache.openejb.core.transaction.TransactionPolicy.commitTransaction(TransactionPolicy.java:141)
	at
org.apache.openejb.core.transaction.TxRequired.afterInvoke(TxRequired.java:75)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:233)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
	at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
	at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:321)
	at
org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
	at $Proxy96.addMatches(Unknown Source)
	at
englrn.matchmaker.matching.web.LoginBackingBean.addSelectedInternItems(LoginBackingBean.java:570)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
	at
com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
	at
javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:75)
	at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:54)
	at javax.faces.component.UICommand.broadcast(UICommand.java:121)
	at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:292)
	at javax.faces.component.UIViewRoot.process(UIViewRoot.java:209)
	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:117)
	at
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
	at
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:103)
	at
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:148)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at
org.apache.geronimo.jetty6.InternalJettyServletHolder.handle(InternalJettyServletHolder.java:65)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
	at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at
org.apache.geronimo.jetty6.handler.TwistyWebAppContext.access$101(TwistyWebAppContext.java:40)
	at
org.apache.geronimo.jetty6.handler.TwistyWebAppContext$TwistyHandler.handle(TwistyWebAppContext.java:65)
	at
org.apache.geronimo.jetty6.handler.ThreadClassloaderHandler.handle(ThreadClassloaderHandler.java:46)
	at
org.apache.geronimo.jetty6.handler.InstanceContextHandler.handle(InstanceContextHandler.java:58)
	at
org.apache.geronimo.jetty6.handler.UserTransactionHandler.handle(UserTransactionHandler.java:48)
	at
org.apache.geronimo.jetty6.handler.ComponentContextHandler.handle(ComponentContextHandler.java:47)
	at
org.apache.geronimo.jetty6.handler.TwistyWebAppContext.handle(TwistyWebAppContext.java:59)
	at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
	at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:324)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
	at
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
	at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
	at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
	at
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
	at java.lang.Thread.run(Thread.java:595)
Caused by: <openjpa-1.0.1-r420667:592145 nonfatal store error>
org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock
violation was detected when flushing object instance
"englrn.matchmaker.model.Request-265" to the data store.  This indicates
that the object was concurrently modified in another transaction.
FailedObject: englrn.matchmaker.model.Request-265
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:160)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:85)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
	... 65 more
NestedThrowables:
<openjpa-1.0.1-r420667:592145 nonfatal store error>
org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock
violation was detected when flushing object instance
"englrn.matchmaker.model.ChoiceIntern-951" to the data store.  This
indicates that the object was concurrently modified in another transaction.
FailedObject: englrn.matchmaker.model.ChoiceIntern-951
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:101)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:73)
	at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryRow(OperationOrderUpdateManager.java:203)
	at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush(OperationOrderUpdateManager.java:89)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1954)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
	at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
	at
org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:245)
	at
org.apache.openejb.core.transaction.TransactionPolicy.commitTransaction(TransactionPolicy.java:141)
	at
org.apache.openejb.core.transaction.TxRequired.afterInvoke(TxRequired.java:75)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:233)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
	at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
	at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:321)
	at
org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
	at $Proxy96.addMatches(Unknown Source)
	at
englrn.matchmaker.matching.web.LoginBackingBean.addSelectedInternItems(LoginBackingBean.java:570)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
	at
com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
	at
javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:75)
	at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:54)
	at javax.faces.component.UICommand.broadcast(UICommand.java:121)
	at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:292)
	at javax.faces.component.UIViewRoot.process(UIViewRoot.java:209)
	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:117)
	at
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
	at
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:103)
	at
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:148)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at
org.apache.geronimo.jetty6.InternalJettyServletHolder.handle(InternalJettyServletHolder.java:65)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
	at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at
org.apache.geronimo.jetty6.handler.TwistyWebAppContext.access$101(TwistyWebAppContext.java:40)
	at
org.apache.geronimo.jetty6.handler.TwistyWebAppContext$TwistyHandler.handle(TwistyWebAppContext.java:65)
	at
org.apache.geronimo.jetty6.handler.ThreadClassloaderHandler.handle(ThreadClassloaderHandler.java:46)
	at
org.apache.geronimo.jetty6.handler.InstanceContextHandler.handle(InstanceContextHandler.java:58)
	at
org.apache.geronimo.jetty6.handler.UserTransactionHandler.handle(UserTransactionHandler.java:48)
	at
org.apache.geronimo.jetty6.handler.ComponentContextHandler.handle(ComponentContextHandler.java:47)
	at
org.apache.geronimo.jetty6.handler.TwistyWebAppContext.handle(TwistyWebAppContext.java:59)
	at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
	at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:324)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
	at
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
	at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
	at org.apache.geronimo.pool.ThreadPool$1.run(ThreadPool.java:214)
	at
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:344)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
	at java.lang.Thread.run(Thread.java:595)

-- 
View this message in context: http://www.nabble.com/OptimisticLockException-confusion.-tp17243604p17243604.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message