mit(JDBCTransaction.java:86)
I get no exception if the DesignColourOptionCollection is empty, only if it has objects in as well. So if the parent object only has a SizeOptionCollection, the delete goes fine.
Relevant bits of HBM files:-Code:
lt;setname=quot;sizeOptionCollectionquot;lazy=quot;truequot;inverse=quot;truequot;cascade=quot;all-delete-orphanquot;sort=quot;unsortedquot;order-by=quot;ORDER_KEY ascquot; gt;
lt;key column=quot ARENT_PRODUCT_FKquot;gt;lt;/keygt;
lt;one-to-many class=quot;org.bto.btoscommon.model.SizeOptionquot;/gt;
lt;/setgt;
lt;setname=quot;designColourOptionCollectionquot;lazy=quot;truequot;inverse=quot;truequot;cascade=quot;all-delete-orphanquot;sort=quot;unsortedquot;order-by=quot;ORDER_KEY ascquot; gt;
lt;key column=quot ARENT_PRODUCT_FKquot;gt;lt;/keygt;
lt;one-to-many class=quot;org.bto.btoscommon.model.DesignColourOptionquot;/gt;
lt;/setgt;
Code:
lt;many-to-onename=quot;parentProductquot;class=quot;org.bto.btoscommon.model.Productquot;cascade=quot;allquot;outer-join=quot;autoquot;update=quot;truequot;insert=quot;truequot;column=quot ARENT_PRODUCT_FKquot;not-null=quot;truequot; /gt;
I'm sure this is a Hibernate config issue, but I can't see it.
Bob
Found the problem. Didn't want the cascade in the many-to-one statement.
Bob
When you delete an object from hibernate you have to delete it from *all* collections it exists in...
Originally Posted by yatescoWhen you delete an object from hibernate you have to delete it from *all* collections it exists in...
I know, they only exist in one location. I guess SizeOption makes it sound like they are constants but they aren't. Each product has it's own individual options since in my requirements different sizes can have different prices for each product.
The problem was that if I deleted a SizeOption then Hibernate threw an ObjectDeletedException about the DesignColourOptionCollection even if I hadn't touched that collection.
The reason this only just came up is because I'm generating my Hibernate entities with Andromda and my velocity template had cascade=quot;allquot; on the many-to-one relationship. I'd never noticed this before since none of my other objects contains more than one child collection.
I guess what was happening was that for some reason Hibernate saw the cascade=quot;allquot; on the SizeOption when it was deleted and then moving up the tree to the Product and seeing a cascade=quot;all-delete-orphanquot; there, decided it was going to try and do something with the DesignColourOptionCollection.
Removing the cascade on the many-to-one relationship in my velocity template has solved the problem.
Bob |