posted 19 years ago
Hi all,
I 'm trying the mapping for One-to-Many( One Customer has many Address).
with the foreign key relationship in the Address Table
I have collection of Address in Customer.
then i 'm inserting the Customer using sessionVar.save(customer)
So I 'm getting the following query and Data was inserted fine.
But my issue here is, on the line numbers [2]and [3], address data been inserted with the foreign key [CUSID],even then it is firing two more quries to update CUSID.
I feel it is unnecessary. With this posting i have given my mapping files for both address and Customer. Plz guide me if anything i need to do to avoid this.
[1]insert into CUSTOMER (NAME, CID) values ('ABC', 4)
[2]insert into ADDRESS (ADDRESS, CUSID, ADDID) values ('Address', 4, 7)
[3]insert into ADDRESS (ADDRESS, CUSID, ADDID) values ('Address2',4, 8)
[4]update ADDRESS set CUSID=4, POSITION=0 where ADDID=7
[5]update ADDRESS set CUSID=4, POSITION=1 where ADDID=8
---------------------
Mapping file for Customer
<hibernate-mapping package="mapping/one2many/set">
<class name="Customer" table="CUSTOMER" lazy="true" >
<id name="cusId" type="long" column="CID">
<generator class="increment"/>
</id>
<property name="name" column="NAME" access="field" />
<set name="addresses" table="ADDRESS" cascade="all">
<key column="CUSID"/>
<one-to-many class="Address"/>
</set>
</class>
</hibernate-mapping>
-----------------------------
Mapping file for
<hibernate-mapping package="mapping/one2many/set">
<class name="Address" table="ADDRESS" proxy="Address" lazy="true" >
<id name="addId" type="long" column="ADDID">
<generator class="increment"/>
</id>
<property name="address" column="ADDRESS"/>
<many-to-one name="customer" column="CUSID" cascade="all" class="Customer" />
</class>
</hibernate-mapping>
Regards,
Selva varadhan