aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate causing Concurrent Modification Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate causing Concurrent Modification Exception" Watch "Hibernate causing Concurrent Modification Exception" New topic
Author

Hibernate causing Concurrent Modification Exception

Anton Lokotsch
Greenhorn

Joined: Feb 05, 2004
Posts: 3
Hibernate 2.18 and JBOSS 4.0.0 and MYSQL 4.1

Please could someone assist with this bizarre problem:

whenever i attempt an UPDATE of a loaded object i get a ConcurrentModificationException. All I am doing is
1) get new session from sessionfactory
2) load object
3) change object
4) commit changes

I have Hibernate working within a stateless session bean environment with business methods such as add,update etc called using an axis webservice.
The code is as simple as

Session session=null;
CollectionDetailsType colDetails=null;
CollectionDetailsTypeImpl();
try{
//open session
session=sf.openSession();
//begin transaction
net.sf.hibernate.Transaction t=session.beginTransaction();
//load db object
colDetails=(CollectionDetailsType)session.getCollectionDetailsTypeImpl.class,new Integer(1));
//change something
colDetails.setInitialDebt(new Double(1.00));
//commit
t.commit();
session.close();
}catch(HibernateException he){

Does anyone have any ideas as to why on earth this is happening in such a simple case of update?
Anton Lokotsch
Greenhorn

Joined: Feb 05, 2004
Posts: 3
We suspected it was a mapping issue. All our cascades were set to "all". So we played with the various options. Eventually cascade="delete-orphan" allows the update to complete without any ConcurrentModificationException. The Hibernate book states that this "will delete any persistent entity instance that has been removed (dereferenced) from the association (for example, from a collection)"

The reason why I have orphans is puzzling. Any ideas? Below is the mapping:

<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="delete-orphan" inverse="false" lazy="false">
<key column="collectionID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.TransactionTypeImpl"/>
</bag>

<bag name="collectionDetails" cascade="delete-orphan" inverse="false" lazy="false">
<key column="collectionID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.CollectionDetailsTypeImpl"/>
</bag>

<bag name="party" cascade="delete-orphan" inverse="false" lazy="false">
<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="false">
<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="false">
<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="delete-orphan" inverse="false" lazy="false">
<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="false">
<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" />

<bag name="assetDescription" cascade="delete-orphan" inverse="false" lazy="false">
<key column="collectionDetailsID"/>
<one-to-many class="za.co.lawactive.tpe.dao.impl.AssetDescriptionTypeImpl"/>
</bag>

<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>



<!-- 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="delete-orphan" inverse="false" lazy="false">
<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="reflexMT"/>


</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="false"
>
<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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate causing Concurrent Modification Exception