Hi,
I am facing a problem in Hibernate cascade update. I have a Customer with a mapping set of Pieces (with CustomerPiece-mapping in the middle)
Customer.hbm.xml:
...
...
<set name="pieces" table="customer_piece" lazy="true">
<key column="customer_id" />
<many-to-many column="piece_id" class="fi.saha.hibernate.Piece" />
</set>
CustomerPiece.hbm.xml:
...
...
<many-to-one name="customer" class="fi.saha.hibernate.Customer" insert="false" update="false" column="customer_id" />
So the DB-structure goes like customer=>customer_piece=>piece.
When I try to update the customer instance with a new set of Pieces, Hibernate first deletes all the rows from customer_piece -table and then inserts them again (see the generated SQL below).
CustomerPiece -table holds valuable information for our software and thus all the rows must not be deleted from that table at the beginning of the update.
How can I prevent Hibernate from deleting all the rows at first from "customer_piece" in the cascade update and instead only delete those not in the updated Set and add the new ones?
regards,
Jari Laitinen
Hibernate version:
3.0
Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
15:29:23,484 INFO [STDOUT] Hibernate: update customer set NAME=?, PASSWORD=?, PIECE_LIMIT=?, DATABASE_NAME=?, ACTIVE=?, LAST_VISIT=?, TYPE=?, START_DATE=?, END_DATE=?, CUSTOMER=?, VERSION=?, CONTACT=?, STREETADDRESS=?, POSTALADDRESS=?, INFO=?, INFO2=?, GSM=?, PHONE=?, EMAIL=?, ONLINE_ORDER=?, LOGGED=?, DATE_UPDATED=?, UPDATE_FLAG=?, EXTRANET_PASSWORD=?, HALT_FLAG=? where ID=?
15:29:23,484 INFO [STDOUT] Hibernate: delete from customer_piece where customer_id=?
15:29:23,500 INFO [STDOUT] Hibernate: insert into customer_piece (customer_id, piece_id) values (?, ?)
etc...
etc...
|