I've got a performance object and within it a collection of deliverables (as a set). On initial creation everything works wonderfully. However when I update or remove an item from the collection or ad a new object to it as an update I get NULL insert errors. Using Hibernate I'm not updating the individual items in the collection I'm updating the "parent" object and would assume that it could tell what within it needs an update and what needs an insert. There are performanceID and deliverableID (both Longs) within the Deliverable objects, do they need to be set to something specific for this to function (or will 0 or null work?)
the following is the error that I'm currently getting when simply updating the current deliverables (everything has non-null id's)...
there are 4 deliverables associated with this particular performance report and they seem to be updated appropriately but I don't know where the last "update tblDeliverable set PerformanceID=null where PerformanceID=?" is coming from
Thanks for the help there boys and girls... I was fighting the urge to try it out but with a profound lack of response I figured I might as well give it a go... easily one of the most idiotic mechanisms that I have ever encountered is the need to have a parent object as a property of the child object of a collection to get it working properly... so astoundingly non-object oriented it's not funny... oh well... for those of you encountering a similar issue in the parent xml declaration use a one-to-many relationship with cascade="all-delete-orphan" inverse="true" and a many-to-one relationship in the child and yes you will need to have the parent object as a property of the child (which will undoubtedly contain references to all the other children, which will contain references to their parent... etc.)... wow...
I had similar problem just yesterday! In our case, we were mapping 2 tables with "unidirectional" one-to-many association on foreign key. Based on the Hibernate reference document, quote from 7.2.3
"A unidirectional one-to-many association on a foreign key is a very unusual case, and is not really recommended." Looks like Hibernate really doesn't like this type of association or database design - for some reason, Hibernate will issue "update to set to null" and this will fail if you define the foreign key column in the child table to be "not null"
Hmm...I am not convinced it is "very unusual"....and there is nothing wrong to define the foreign key column to be NOT NULL based on our business logic....
Anyway, the mapping files in our approach are very like those in the reference doc:
in the parent class mapping file, have "not-null"="true" in the key column and remove the defination of the foreign key property from the child mapping file (otherwise we had duplicate mapping error)
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com