Hibernate 3.1rc2
Annotations 3.1beta6
JDK 1.5.05
Well, I wonder if this is allowed usage or if it is a Hibernate bug.
List<Cart> carts = cartFinder.findCarts("XYZ*");
for(Cart cart : carts)
{
for(Item item : cart.getItems())
editor.deleteItem(item);
// The below line is what causes the update() problem.
// If commented out, everything works as expected. Ie. all
// Item and Book table entries are deleted properly -- confirmed!
// So if all items associated with 'cart' are gone, why the update()
// problem?
editor.deleteCart(cart );
}
trans.commit();
editor.delete() is essentially a hibernte session.delete(obj)...
Item is the base class. Actual instance is Book.
So, Item <- Book.
Each Cart has a PK cartId.
Each Item has a itemId as PK.
Each Item has a cartId as FK (not part of item PK).
green_fr wrote:
It happens when your child table has a composite key.
For instance, your tables are ORDER (order_id key), PRODUCT (product_id key) and DETAIL (order_id + product_id composite key).
When mapping DETAIL as a set, like for example:
<class name="Detail" table="DETAIL">
<composite-id>
<key-property name="order_id" />
<key-property name="product_id" />
</composite-id>
</class>
<class name="Order" table="ORDER">
<id name="order_id" />
<set name="details" cascade="all ">
<key column="product_id" />
<one-to-many class="Detail" />
</set>
</class>
You’ll get the same trace when deleting Order object:
[24/11/05 14:28:44:157 CET] 10ff10ff SystemOut U Hibernate: update DETAIL set order_id=null where order_id=?
With evidently the same exception:
[WARN] JDBCExceptionReporter - SQL Error: 1407, SQLState: 72000
[ERROR] JDBCExceptionReporter - ORA-01407: cannot update ("DETAIL"."order_id") to NULL
I played with cascade property but didn’t find the good one.