hibernate version: 2
mapping doc:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="entities">
<class
name="Order"
table="[Order]"
dynamic-update="true"
dynamic-insert="true"
>
<id name="orderId" column="orderId">
<generator class="identity"/>
</id>
<property
name="orderDate"
not-null="true"
length="4"
type="timestamp"
unique="false"
/>
<set
name="orderItems"
table="OrderItem"
lazy="true"
cascade="all"
>
<key column="OrderId"/>
<composite-element class="OrderItem">
<property name="amount"/>
<property name="price"/>
<many-to-one name="product" column="productId"/>
</composite-element>
</set>
</class>
</hibernate-mapping>
database: MSSQL2000 using jdbc driver from microsoft
tables: order, orderItem and product
relations: order can have one-to-many orderItems
product can be part of one-to-many orderItems
problem:
It is not really a problem, it just a concern...
It all happens when I was inserting an Order with various OrderItems, the Order was inserted along with all its OrderItems but a strange SQL DELETE statement was excecuted during the operation
Hibernate: insert into [Order] (orderDate) values (?) select SCOPE_IDENTITY()
Hibernate: insert into OrderItem (OrderId, amount, price, productId) values (?, ?, ?, ?)
Hibernate: delete from OrderItem where OrderId=? and amount=? and price=? and productId=?
Hibernate: insert into OrderItem (OrderId, amount, price, productId) values (?, ?, ?, ?)
Is this a normal behavior of hibernate? why it tries to delete from the join table?