Problem description:
When I try to update a List of objects I get a ConcurrentModificationException on commit. I am hoping it is a mapping issue but cant pinpoint the cause myself. I have tried forcing session.update(), session.flush() but the same problem occurs. I have been struggling with this for a while and any suggestions would be much appreciated.
Hibernate version:
2.1.8 running on JBOSS 4.0.0
Mapping documents:
Code:
<hibernate-mapping>
<!-- Collection-->
<class name="za.co.lawactive.tpe.dao.impl.CollectionImpl"
table="collection">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="idNo"/>
<property name="branch"/>
<property name="status" />
<property name="department"/>
<property name="province"/>
<property name="division"/>
<bag name="transaction" cascade="all" inverse="true" lazy="true">
<key column="collectionID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.TransactionTypeImpl"/>
</bag>
<bag name="collectionDetails" cascade="all" inverse="true" lazy="true">
<key column="collectionID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.CollectionDetailsTypeImpl"/>
</bag>
<bag name="party" cascade="all" inverse="true" lazy="true">
<key column="collectionID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.PartyTypeImpl"/>
</bag>
</class>
<!-- Address -->
<class name="za.co.lawactive.tpe.dao.impl.AddressTypeImpl"
table="address"
dynamic-update="true">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="type"/>
<property name="line1" />
<property name="line2"/>
<property name="line3"/>
<property name="line4"/>
<property name="code" />
<property name="actionDate" />
<many-to-one name="party" class="za.co.lawactive.tpe.dao.impl.PartyTypeImpl" column="partyID"/>
</class>
<!-- Party -->
<class name="za.co.lawactive.tpe.dao.impl.PartyTypeImpl"
table="party" dynamic-update="true">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="lastName"/>
<property name="firstNames"/>
<property name="title"/>
<property name="initials"/>
<property name="homeTel"/>
<property name="workTel"/>
<property name="cellTel"/>
<property name="otherTel"/>
<property name="email" />
<property name="idNo"/>
<property name="maritalStatus"/>
<bag name="address" cascade="all" inverse="true" lazy="true">
<key column="partyID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.AddressTypeImpl"/>
</bag>
<many-to-one name="collection" class="za.co.lawactive.tpe.dao.impl.CollectionImpl" column="collectionID"/>
</class>
<!-- CollectionDetails-->
<class name="za.co.lawactive.tpe.dao.impl.CollectionDetailsTypeImpl"
table="collectiondetails"
dynamic-update="true">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="initialDebt"/>
<property name="accountNo" />
<property name="balanceOutstanding"/>
<property name="arrearAmount" />
<property name="arrearInterest" />
<property name="agreementType" />
<property name="agreementDate" />
<property name="lastPaymentDate" />
<property name="lastPayment" />
<many-to-one name="collection" class="za.co.lawactive.tpe.dao.impl.CollectionImpl" column="collectionID"/>
</class>
<!--
<class name="za.co.lawactive.tpe.dao.impl.AssetDescriptionTypeImpl"
table="assetdescription">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="description"/>
<many-to-one name="collectionDetails" class="za.co.lawactive.tpe.dao.impl.CollectionDetailsTypeImpl" column="collectionDetailsID"/>
</class>
-->
<!-- Payment
<class name="za.co.lawactive.tpe.dao.impl.PaymentTypeImpl"
table="payment">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="type"/>
<property name="amount"/>
<property name="date" />
<many-to-one name="transaction" class="za.co.lawactive.tpe.dao.impl.TransactionTypeImpl" column="transactionID"/>
</class>
-->
<!-- Description -->
<class name="za.co.lawactive.tpe.dao.impl.TransactionDescriptionTypeImpl"
table="transactiondescription">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="description"/>
<many-to-one name="transaction" class="za.co.lawactive.tpe.dao.impl.TransactionTypeImpl" column="transactionID"/>
</class>
<!-- Transaction-->
<class name="za.co.lawactive.tpe.dao.impl.TransactionTypeImpl"
table="transaction">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="collectionID" update="false" insert="false"/>
<property name="messageID" />
<property name="accountNo" />
<property name="sender"/>
<property name="senderUser" />
<property name="recipient"/>
<property name="recipientUser"/>
<property name="status"/>
<property name="date" />
<property name="actionDate" />
<bag name="transactionDescription" cascade="all" inverse="true" lazy="true">
<key column="transactionID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.TransactionDescriptionTypeImpl"/>
</bag>
<many-to-one name="collection" class="za.co.lawactive.tpe.dao.impl.CollectionImpl" column="collectionID"/>
</class>
<class name="za.co.lawactive.tpe.dao.TimerSetup"
table="TimerSetup">
<id name="messageID" column="messageID" type="java.lang.Integer" unsaved-value="null">
<generator class="assigned" />
</id>
<property name="action"/>
<property name="waitMT"/>
<property name="duration"/>
<property name="expiredMT"/>
</class>
<class name="za.co.lawactive.tpe.dao.Timers"
table="Timers">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="colID"/>
<property name="accountNo"/>
<property name="MTWatch"/>
<property name="expiredMT"/>
<property name="endTime"/>
<property name="recipient"/>
</class>
<class name="za.co.lawactive.tpe.util.panel.dao.impl.PanelItemTypeImpl"
table="userpanel"
dynamic-update="true"
>
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="identity" />
</id>
<property name="lawUserID"/>
<property name="parentID"/>
<property name="userTypeCode"/>
<property name="regionCode"/>
<property name="userName"/>
<property name="rating"/>
</class>
<class name="za.co.lawactive.tpe.util.messages.dao.impl.MessageTypeImpl"
table="messagetypes">
<id name="messageID" column="messageID" type="java.lang.Integer" unsaved-value="null">
<generator class="assigned" />
</id>
<property name="description"/>
<property name="userTypeCode"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
session=sf.openSession();
za.co.lawactive.tpe.dao.TransactionType trans=new TransactionTypeImpl();
StringBuffer getTransactions=new StringBuffer()
.append("FROM ").append(TransactionType.class.getName())
.append(" t WHERE t.collectionID=").append(collectionID).append(" and t.accountNo=")
.append(accountNo).append(" and t.messageID in ").append("(2302)");//mtList);
TransactionType thisTrans=new TransactionTypeImpl();
java.util.List transactionList=session.find(getTransactions.toString());
TransactionType id=null;
net.sf.hibernate.Transaction t=session.beginTransaction();
for(int i=0;i<transactionList.size();i++){
id=(TransactionTypeImpl)transactionList.get(i);
log.info("id: "+id.getId());
log.info("setting new status");
id.setStatus(newStatus);
//session.update(id); doesnt help either
}
t.commit();
log.info("closing session");
session.close();
Full stack trace of any exception that occurs:Code:
17:12:41,888 INFO [STDOUT] Exception of type: java.util.ConcurrentModificationE
xception
17:12:41,888 INFO [STDOUT] java.util.ConcurrentModificationException
17:12:41,904 INFO [STDOUT] at java.util.HashMap$HashIterator.nextEntry(Hash
Map.java:782)
17:12:41,904 INFO [STDOUT] at java.util.HashMap$ValueIterator.next(HashMap.
java:812)
17:12:41,904 INFO [STDOUT] at net.sf.hibernate.impl.Printer.toString(Printe
r.java:82)
17:12:41,904 INFO [STDOUT] at net.sf.hibernate.impl.SessionImpl.flushEveryt
hing(SessionImpl.java:2302)
17:12:41,904 INFO [STDOUT] at net.sf.hibernate.impl.SessionImpl.flush(Sessi
onImpl.java:2260)
17:12:41,904 INFO [STDOUT] at net.sf.hibernate.transaction.JTATransaction.c
ommit(JTATransaction.java:52)
17:12:41,904 INFO [STDOUT] at za.co.lawactive.tpe.ejb.StannicSession.change
Status(StannicSession.java:636)
17:12:41,904 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
17:12:41,904 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
17:12:41,904 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
17:12:41,904 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:3
24)
17:12:41,904 INFO [STDOUT] at org.jboss.invocation.Invocation.performCall(I
nvocation.java:345)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.StatelessSessionContainer$Conta
inerInterceptor.invoke(StatelessSessionContainer.java:214)
17:12:41,904 INFO [STDOUT] at org.jboss.resource.connectionmanager.CachedCo
nnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.StatelessSessionInstanc
eInterceptor.invoke(StatelessSessionInstanceInterceptor.java:113)
17:12:41,904 INFO [STDOUT] at org.jboss.webservice.server.ServiceEndpointIn
terceptor.invoke(ServiceEndpointInterceptor.java:106)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.CallValidationIntercept
or.invoke(CallValidationInterceptor.java:48)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
nvokeNext(AbstractTxInterceptor.java:105)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.runWit
hTransactions(TxInterceptorCMT.java:316)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:149)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.SecurityInterceptor.inv
oke(SecurityInterceptor.java:128)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.LogInterceptor.invoke(L
ogInterceptor.java:191)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.plugins.ProxyFactoryFinderInter
ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.SessionContainer.internalInvoke
(SessionContainer.java:624)
17:12:41,904 INFO [STDOUT] at org.jboss.ejb.Container.invoke(Container.java
:854)
17:12:41,904 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
17:12:41,904 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
17:12:41,904 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
17:12:41,904 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:3
24)
17:12:41,904 INFO [STDOUT] at org.jboss.mx.interceptor.ReflectedDispatcher.
invoke(ReflectedDispatcher.java:141)
17:12:41,904 INFO [STDOUT] at org.jboss.mx.server.Invocation.dispatch(Invoc
ation.java:80)
17:12:41,904 INFO [STDOUT] at org.jboss.mx.server.Invocation.invoke(Invocat
ion.java:72)
17:12:41,982 INFO [STDOUT] at org.jboss.mx.server.AbstractMBeanInvoker.invo
ke(AbstractMBeanInvoker.java:242)
17:12:41,982 INFO [STDOUT] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
eanServerImpl.java:642)
17:12:41,982 INFO [STDOUT] at org.jboss.webservice.server.InvokerProviderEJ
B.invokeServiceEndpoint(InvokerProviderEJB.java:128)
17:12:41,982 INFO [STDOUT] at org.jboss.webservice.server.InvokerProvider.i
nvokeMethod(InvokerProvider.java:347)
17:12:41,982 INFO [STDOUT] at org.apache.axis.providers.java.RPCProvider.in
vokeTarget(RPCProvider.java:177)
17:12:41,982 INFO [STDOUT] at org.apache.axis.providers.java.RPCProvider.pr
ocessMessage(RPCProvider.java:122)
17:12:41,982 INFO [STDOUT] at org.apache.axis.providers.java.JavaProvider.i
nvoke(JavaProvider.java:360)
17:12:41,982 INFO [STDOUT] at org.apache.axis.strategies.InvocationStrategy
.visit(InvocationStrategy.java:73)
17:12:41,982 INFO [STDOUT] at org.apache.axis.SimpleChain.doVisiting(Simple
Chain.java:162)
17:12:41,982 INFO [STDOUT] at org.apache.axis.SimpleChain.invoke(SimpleChai
n.java:125)
17:12:41,982 INFO [STDOUT] at org.apache.axis.handlers.soap.SOAPService.inv
oke(SOAPService.java:557)
17:12:41,982 INFO [STDOUT] at org.jboss.webservice.server.ServerEngine.invo
keInternal(ServerEngine.java:202)
17:12:41,982 INFO [STDOUT] at org.jboss.webservice.server.ServerEngine.invo
ke(ServerEngine.java:91)
17:12:41,982 INFO [STDOUT] at org.apache.axis.transport.http.AxisServlet.do
Post(AxisServlet.java:971)
17:12:41,982 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:717)
17:12:41,982 INFO [STDOUT] at org.apache.axis.transport.http.AxisServletBas
e.service(AxisServletBase.java:372)
17:12:42,045 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:810)
17:12:42,045 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:237)
17:12:42,045 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:157)
17:12:42,045 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilte
r.doFilter(ReplyHeaderFilter.java:75)
17:12:42,045 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:186)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:157)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve
.invoke(StandardWrapperValve.java:214)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve
.invokeInternal(StandardContextValve.java:198)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve
.invoke(StandardContextValve.java:152)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
17:12:42,060 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipal
Valve.invoke(CustomPrincipalValve.java:44)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:102)
17:12:42,060 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssocia
tionValve.invoke(SecurityAssociationValve.java:169)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:102)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.in
voke(StandardHostValve.java:137)
17:12:42,060 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
17:12:42,138 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.i
nvoke(ErrorReportValve.java:118)
17:12:42,138 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:102)
17:12:42,138 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
17:12:42,138 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.
invoke(StandardEngineValve.java:109)
17:12:42,138 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext
.invokeNext(StandardValveContext.java:104)
17:12:42,138 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.inv
oke(StandardPipeline.java:520)
17:12:42,138 INFO [STDOUT] at org.apache.catalina.core.ContainerBase.invoke
(ContainerBase.java:929)
17:12:42,138 INFO [STDOUT] at org.apache.coyote.tomcat5.CoyoteAdapter.servi
ce(CoyoteAdapter.java:160)
17:12:42,138 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.proc
ess(Http11Processor.java:799)
17:12:42,138 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http1
1ConnectionHandler.processConnection(Http11Protocol.java:705)
17:12:42,138 INFO [STDOUT] at org.apache.tomcat.util.net.TcpWorkerThread.ru
nIt(PoolTcpEndpoint.java:577)
17:12:42,138 INFO [STDOUT] at org.apache.tomcat.util.threads.ThreadPool$Con
trolRunnable.run(ThreadPool.java:683)
17:12:42,138 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)
Name and version of the database you are using: MYSQL 4.017 with MYISAM tables
The generated SQL (show_sql=true):Code:
17:12:41,779 INFO [STDOUT] Hibernate: select transactio0_.transactionID as tran
sact3___, transactio0_.id as id__, transactio0_.id as id0_, transactio0_.descrip
tion as descript2_0_, transactio0_.transactionID as transact3_0_ from transactio
ndescription transactio0_ where transactio0_.transactionID=?
17:12:41,779 INFO [STDOUT] Hibernate: select transactio0_.collectionID as colle
cti2___, transactio0_.id as id__, transactio0_.id as id0_, transactio0_.collecti
onID as collecti2_0_, transactio0_.messageID as messageID0_, transactio0_.accoun
tNo as accountNo0_, transactio0_.sender as sender0_, transactio0_.senderUser as
senderUser0_, transactio0_.recipient as recipient0_, transactio0_.recipientUser
as recipien8_0_, transactio0_.status as status0_, transactio0_.date as date0_, t
ransactio0_.actionDate as actionDate0_ from transaction transactio0_ where trans
actio0_.collectionID=?
17:12:41,810 INFO [STDOUT] Hibernate: select collection0_.collectionID as colle
ct11___, collection0_.id as id__, collection0_.id as id0_, collection0_.initialD
ebt as initialD2_0_, collection0_.accountNo as accountNo0_, collection0_.balance
Outstanding as balanceO4_0_, collection0_.arrearAmount as arrearAm5_0_, collecti
on0_.arrearInterest as arrearIn6_0_, collection0_.agreementType as agreemen7_0_,
collection0_.agreementDate as agreemen8_0_, collection0_.lastPaymentDate as las
tPaym9_0_, collection0_.lastPayment as lastPay10_0_, collection0_.collectionID a
s collect11_0_ from collectiondetails collection0_ where collection0_.collection
ID=?
17:12:41,857 INFO [STDOUT] Hibernate: select party0_.collectionID as collect13_
__, party0_.id as id__, party0_.id as id0_, party0_.lastName as lastName0_, part
y0_.firstNames as firstNames0_, party0_.title as title0_, party0_.initials as in
itials0_, party0_.homeTel as homeTel0_, party0_.workTel as workTel0_, party0_.ce
llTel as cellTel0_, party0_.otherTel as otherTel0_, party0_.email as email0_, pa
rty0_.idNo as idNo0_, party0_.maritalStatus as marital12_0_, party0_.collectionI
D as collect13_0_ from party party0_ where party0_.collectionID=?
17:12:41,888 INFO [STDOUT] Hibernate: select transactio0_.transactionID as tran
sact3___, transactio0_.id as id__, transactio0_.id as id0_, transactio0_.descrip
tion as descript2_0_, transactio0_.transactionID as transact3_0_ from transactio
ndescription transactio0_ where transactio0_.transactionID=?