You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by BKumar <bi...@creditpointe.com> on 2013/01/22 08:08:55 UTC
Optimi sticLockException: Optimistic locking errors were detected
when flushing to the data store
Hi All,
This is related to CMP2.1 on tomee+.
I am getting Optimisticlockexception. When calling remove for both child
and parent.
1. I am getting below exception when I call remove on both
"RuleConditionBean"(Child) and "RuleBean"(parent).
2. I don't get exception when I all remove only on RuleBean(Parent).
As I want to follow the first way only because don't want to change my
existing code.
openejb-orm.xml:
<entity class="openejb.com.rage.rule.dal.ejb.RuleBean" name="RuleBean">
<description>Rule#RuleBean</description>
<named-query
name="RuleBean.findByRuleNameAppId(java.lang.String,java.lang.Integer)">
<query>SELECT OBJECT(r) FROM RuleBean AS r WHERE (r.rule_Name = ?1 AND
r.appl_Seq_Id = ?2)</query>
</named-query>
<attributes>
<id name="rule_Seq_Id">
<column name="RULE_SEQ_ID" />
<generated-value strategy="TABLE" generator="RD_SEQUENCE" />
</id>
<basic name="appl_Seq_Id">
<column name="APPL_SEQ_ID" />
</basic>
<basic name="rule_Name">
<column name="RULE_NAME" />
</basic>
<one-to-many mapped-by="rule" name="ruleConditions">
<cascade>
<cascade-All/>
</cascade>
</one-to-many>
</attributes>
</entity>
<entity class="openejb.com.rage.rule.dal.ejb.RuleConditionBean"
name="RuleConditionBean">
<description>Rule#RuleConditionBean</description>
<id-class class="com.rage.rule.dal.ejb.RuleConditionPK" />
<named-query name="RuleConditionBean.findByRuleKey(java.lang.Integer)">
<query>SELECT OBJECT(r) FROM RuleConditionBean AS r WHERE r.rule_Seq_Id =
?1</query>
</named-query>
<attributes>
<id name="rule_Seq_Id">
<column updatable="false" name="RULE_SEQ_ID" />
</id>
<id name="cond_Paramseq_No">
<column updatable="false" name="COND_PARAMSEQ_NO" />
</id>
<basic name="cond_Lhs">
<column name="COND_LHS" />
</basic>
<many-to-one optional="true" name="rule">
<join-column nullable="false" name="RULE_SEQ_ID" />
</many-to-one>
</attributes>
</entity>
-----------------------------------------------------------------------------
WARNING: Unexpected exception from beforeCompletion; transaction will roll
back
<openjpa-2.2.0-r422266:1244990 nonfatal store error>
org.apache.openjpa.persistence.Optimi
sticLockException: Optimistic locking errors were detected when flushing to
the data store
. The following objects may have been concurrently modified in another
transaction: [open
ejb.com.rage.rule.dal.ejb.RuleConditionBean-Rule Condition: Id =
15285Sequence No. = 1]
at
org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2326)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2174)
at
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2072)
at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1990)
at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(Transa
ctionImpl.java:527)
at
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(Transa
ctionImpl.java:512)
at
org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(Transacti
onImpl.java:413)
at
org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.
java:262)
at
org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(Transacti
onManagerImpl.java:252)
at
org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(Jt
aTransactionPolicy.java:328)
at
org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
at
org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransacti
onUtil.java:73)
at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer
.java:257)
at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.
java:189)
at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(Ej
bObjectProxyHandler.java:253)
at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxy
Handler.java:248)
at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler
.java:92)
at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java
:279)
at $Proxy139.delete(Unknown Source)
at com.rage.rule.bizcomp.RuleHandler.service(RuleHandler.java:120)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil
terChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain
.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
222)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
123)
at
org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.ja
va:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:11
8)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processo
r.java:1004)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractPr
otocol.java:589)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310
)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:
886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
--
View this message in context: http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Optimi sticLockException: Optimistic locking errors were
detected when flushing to the data store
Posted by BKumar <bi...@creditpointe.com>.
Hi,
I have created a simple example in which one session bean is performing
delete on entity Movie and director.
Client Object is com.rage.EntityBean1 is present inside the jar only.
Also, there is cascade delete and foreign key constraint on database(Movie)
as well.
EntityBean.jar
<http://openejb.979440.n4.nabble.com/file/n4660345/EntityBean.jar>
Create Script:
CREATE TABLE Director(
[id] [int] IDENTITY(1,1) NOT NULL,
[firstName] [varchar](255) NULL,
[lastName] [varchar](255) NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
))
CREATE TABLE Movie(
[ID] [int] IDENTITY(1,1) NOT NULL,
[title] [varchar](255) NULL,
[year] [int] NULL,
[hjsajdada] [int] NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
))
ALTER TABLE Movie WITH NOCHECK ADD CONSTRAINT FK_COND_MOVIEEQ_ID1 FOREIGN
KEY(hjsajdada)
REFERENCES Director (id)
ON DELETE CASCADE
--
View this message in context: http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338p4660345.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Optimi sticLockException: Optimistic locking errors were detected
when flushing to the data store
Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm please share a mvn project runnable out of the box (not environment
dependent + no external database + sources) to be sure we work on the same
case
*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*
2013/1/22 BKumar <bi...@creditpointe.com>
> Hi,
>
> I have created a simple example in which one session bean is performing
> delete on entity Movie and director.
>
> Client Object is com.rage.EntityBean1 is present inside the jar only.
>
> Also, there is cascade delete and foreign key constraint on table
> Movie(hjsajdada) in database.
>
> EntityBean.jar
> <http://openejb.979440.n4.nabble.com/file/n4660346/EntityBean.jar>
>
> Create Script:
>
> CREATE TABLE Director(
> [id] [int] IDENTITY(1,1) NOT NULL,
> [firstName] [varchar](255) NULL,
> [lastName] [varchar](255) NULL,
> PRIMARY KEY CLUSTERED
> (
> [id] ASC
> ))
>
> CREATE TABLE Movie(
> [ID] [int] IDENTITY(1,1) NOT NULL,
> [title] [varchar](255) NULL,
> [year] [int] NULL,
> [hjsajdada] [int] NULL,
> PRIMARY KEY CLUSTERED
> (
> [ID] ASC
> ))
> ALTER TABLE Movie WITH NOCHECK ADD CONSTRAINT FK_COND_MOVIEEQ_ID1 FOREIGN
> KEY(hjsajdada)
> REFERENCES Director (id)
> ON DELETE CASCADE
>
> Thanks,
> Bibhuti EntityBean.jar
> <http://openejb.979440.n4.nabble.com/file/n4660346/EntityBean.jar>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338p4660346.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: Optimi sticLockException: Optimistic locking errors were
detected when flushing to the data store
Posted by BKumar <bi...@creditpointe.com>.
Hi,
I have created a simple example in which one session bean is performing
delete on entity Movie and director.
Client Object is com.rage.EntityBean1 is present inside the jar only.
Also, there is cascade delete and foreign key constraint on table
Movie(hjsajdada) in database.
EntityBean.jar
<http://openejb.979440.n4.nabble.com/file/n4660346/EntityBean.jar>
Create Script:
CREATE TABLE Director(
[id] [int] IDENTITY(1,1) NOT NULL,
[firstName] [varchar](255) NULL,
[lastName] [varchar](255) NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
))
CREATE TABLE Movie(
[ID] [int] IDENTITY(1,1) NOT NULL,
[title] [varchar](255) NULL,
[year] [int] NULL,
[hjsajdada] [int] NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
))
ALTER TABLE Movie WITH NOCHECK ADD CONSTRAINT FK_COND_MOVIEEQ_ID1 FOREIGN
KEY(hjsajdada)
REFERENCES Director (id)
ON DELETE CASCADE
Thanks,
Bibhuti EntityBean.jar
<http://openejb.979440.n4.nabble.com/file/n4660346/EntityBean.jar>
--
View this message in context: http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338p4660346.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Optimi sticLockException: Optimistic locking errors were
detected when flushing to the data store
Posted by BKumar <bi...@creditpointe.com>.
Hi Romain,
I will try to reproduce with a sample example. Also, in my example all the
transaction attributes are "Required" from session bean to entity bean.
Thanks,
Bibhuti
--
View this message in context: http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338p4660340.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Optimi sticLockException: Optimistic locking errors were detected
when flushing to the data store
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
Can you packe your sample with a unit test please?
Le 22 janv. 2013 08:09, "BKumar" <bi...@creditpointe.com> a écrit :
> Hi All,
>
> This is related to CMP2.1 on tomee+.
>
> I am getting Optimisticlockexception. When calling remove for both child
> and parent.
>
> 1. I am getting below exception when I call remove on both
> "RuleConditionBean"(Child) and "RuleBean"(parent).
> 2. I don't get exception when I all remove only on RuleBean(Parent).
>
> As I want to follow the first way only because don't want to change my
> existing code.
>
> openejb-orm.xml:
>
> <entity class="openejb.com.rage.rule.dal.ejb.RuleBean" name="RuleBean">
> <description>Rule#RuleBean</description>
>
>
>
> <named-query
>
> name="RuleBean.findByRuleNameAppId(java.lang.String,java.lang.Integer)">
> <query>SELECT OBJECT(r) FROM RuleBean AS r WHERE
> (r.rule_Name = ?1 AND
> r.appl_Seq_Id = ?2)</query>
> </named-query>
>
> <attributes>
> <id name="rule_Seq_Id">
> <column name="RULE_SEQ_ID" />
> <generated-value strategy="TABLE"
> generator="RD_SEQUENCE" />
> </id>
> <basic name="appl_Seq_Id">
> <column name="APPL_SEQ_ID" />
> </basic>
> <basic name="rule_Name">
> <column name="RULE_NAME" />
> </basic>
>
> <one-to-many mapped-by="rule"
> name="ruleConditions">
> <cascade>
> <cascade-All/>
> </cascade>
> </one-to-many>
> </attributes>
> </entity>
> <entity class="openejb.com.rage.rule.dal.ejb.RuleConditionBean"
> name="RuleConditionBean">
> <description>Rule#RuleConditionBean</description>
>
>
> <id-class class="com.rage.rule.dal.ejb.RuleConditionPK" />
> <named-query
> name="RuleConditionBean.findByRuleKey(java.lang.Integer)">
> <query>SELECT OBJECT(r) FROM RuleConditionBean AS
> r WHERE r.rule_Seq_Id =
> ?1</query>
> </named-query>
> <attributes>
> <id name="rule_Seq_Id">
> <column updatable="false"
> name="RULE_SEQ_ID" />
> </id>
> <id name="cond_Paramseq_No">
> <column updatable="false"
> name="COND_PARAMSEQ_NO" />
> </id>
>
> <basic name="cond_Lhs">
> <column name="COND_LHS" />
> </basic>
>
> <many-to-one optional="true" name="rule">
> <join-column nullable="false"
> name="RULE_SEQ_ID" />
>
> </many-to-one>
> </attributes>
> </entity>
>
> -----------------------------------------------------------------------------
>
> WARNING: Unexpected exception from beforeCompletion; transaction will roll
> back
> <openjpa-2.2.0-r422266:1244990 nonfatal store error>
> org.apache.openjpa.persistence.Optimi
> sticLockException: Optimistic locking errors were detected when flushing to
> the data store
> . The following objects may have been concurrently modified in another
> transaction: [open
> ejb.com.rage.rule.dal.ejb.RuleConditionBean-Rule Condition: Id =
> 15285Sequence No. = 1]
> at
>
> org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2326)
> at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2174)
> at
> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2072)
> at
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1990)
> at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(Transa
> ctionImpl.java:527)
> at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(Transa
> ctionImpl.java:512)
> at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(Transacti
> onImpl.java:413)
> at
>
> org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.
> java:262)
> at
>
> org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(Transacti
> onManagerImpl.java:252)
> at
>
> org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(Jt
> aTransactionPolicy.java:328)
> at
> org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
> at
>
> org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransacti
> onUtil.java:73)
> at
>
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer
> .java:257)
> at
>
> org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.
> java:189)
> at
>
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(Ej
> bObjectProxyHandler.java:253)
> at
>
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxy
> Handler.java:248)
> at
>
> org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler
> .java:92)
> at
>
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java
> :279)
> at $Proxy139.delete(Unknown Source)
> at com.rage.rule.bizcomp.RuleHandler.service(RuleHandler.java:120)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
> at
>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil
> terChain.java:305)
> at
>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain
> .java:210)
> at
>
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
> 222)
> at
>
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
> 123)
> at
> org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
> at
>
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.ja
> va:472)
> at
>
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
> at
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
> at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
> at
>
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:11
> 8)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> at
>
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processo
> r.java:1004)
> at
>
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractPr
> otocol.java:589)
> at
>
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310
> )
> at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:
> 886)
> at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: Optimi sticLockException: Optimistic locking errors were detected
when flushing to the data store
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
all operations done in a transaction are done at commit time but the order
is never guaranteed by any providers (in fact most of them doesn't respect
it at all). So i'm pretty sure that's not the exact reason
*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*
2013/1/28 BKumar <bi...@creditpointe.com>
> It seems I have identified the possible reason.
> In my code first I am calling child remove then parent remove.This is
> the most Ideal way of working the remove.
> But in Tomee+ it seems when transaction is commit, it is first calling
> parent remove and then child remove and at the same time database cascade
> is also trying to delete child because it is getting triggered by parent
> delete.
>
> Is there any way in OpenEjb such that at commit it maintain the order of
> calling remove as in the code?
>
> Thanks,
> Bibhuti
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338p4660429.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: Optimi sticLockException: Optimistic locking errors were
detected when flushing to the data store
Posted by BKumar <bi...@creditpointe.com>.
It seems I have identified the possible reason.
In my code first I am calling child remove then parent remove.This is
the most Ideal way of working the remove.
But in Tomee+ it seems when transaction is commit, it is first calling
parent remove and then child remove and at the same time database cascade
is also trying to delete child because it is getting triggered by parent
delete.
Is there any way in OpenEjb such that at commit it maintain the order of
calling remove as in the code?
Thanks,
Bibhuti
--
View this message in context: http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338p4660429.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Optimi sticLockException: Optimistic locking errors were
detected when flushing to the data store
Posted by AndyG <an...@orprovision.com>.
Are you setting the 'openjpa.RuntimeUnenhancedClasses' property to
'supported', if so don't?
You could also try using
@TransactionManagement(TransactionManagementType.BEAN) and manage your own
transaction.
@Resource
private UserTransaction transaction;
...
transaction.begin();
...
delete
...
transaction.commit();
--
View this message in context: http://openejb.979440.n4.nabble.com/Optimi-sticLockException-Optimistic-locking-errors-were-detected-when-flushing-to-the-data-store-tp4660338p4660352.html
Sent from the OpenEJB User mailing list archive at Nabble.com.