-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many-to-many bridge table saving issue
PostPosted: Sat Mar 03, 2007 12:53 am 
Newbie

Joined: Fri Sep 02, 2005 3:51 pm
Posts: 17
Hi,
We have an application using hibernate 3.0 and spring framework with a mysql 5 database. We have modelled an Order object and a Charge object. An order can have one or more charges. So we modelled this as a many-to-many relationship such that there are 3 tables, order table, charge table and an order_charge table. The order_charge table is a bridge table that simply stores ids from the order and charge tables.

We have a process that reads a huge text file. Each line in the text file generates an order and the corresponding charges. An order object is created, the charge objects are created and added to the collection of charges of the order object. Once the line is processed, the order object is saved by calling a method that is transaction managed by spring (I am referring to all this since I dont know where the problem is!)

The issue we are facing is as follows,
while the text file is being processed, we can see the 2 tables, order and charge, being updated, i.e., the number of rows increases as the text file is read. BUT, the bridge table order_charge has no records until ALL the lines in the text file are processed, although each order is saved separately.

the problem with this is that if for some reason the file processing fails half way, then we have all the order objects and all the charge objects saved, but the association between the order and charge objects (which should be in the order_charge table) is lost.

I have included the hibernate mapping file for the order and charge object . Please help us understand what we are doing wrong here.

Much appreciated.


Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.cwsi.workorder.model">
<class name="WOrder" table="wo_orders">
<id name="id" type="long" column="oid">
<generator class="native"/>
</id>

<set name="charges" lazy="true" table="wo_orders_charges" cascade="save-update">
<key column="oid" not-null="true"/>
<many-to-many class="com.cwsi.workorder.model.WOrderCharge" column="id"/>
</set>


</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="com.cwsi.workorder.model">
<class name="WOrderCharge" table="wo_charge">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="chargeId" type="long" insert="false" update="false"/>
<property name="unitValue" type="float" not-null="true"/>
<property name="unitType" type="int" not-null="false"/>
<property name="ratePerUnit" column="rate_unit" type="float" not-null="true"/>
<property name="totalValue" type="float" not-null="true"/>
<property name="totalValueCharge" type="float" not-null="true"/>
<property name="name" column="name" type="string"/>

<many-to-one name="ediCharge"
class="com.cwsi.workorder.model.EdiCharge"
column="chargeId"
lazy="false"
/>
</class>
</hibernate-mapping>



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.