This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
The weird behavior arises when attaching the file, in the setter method:
The weird thing is, that af is supposed to be a new instance of the AttachedFile class. But what I find out, is that if I debug, inside this method before the assignation is made, af doesn't have its 'id' attribute set (before the assignation it is null), but once the assignation is done, the id member of the AttachedFile instance af is indeed populated. So it seems Hibernate populates this data automatically.
This is leading me to the problem of ConstraintViolationException's being triggered when saving the Contract instance, since the id created for the AttachedFile instance doesn't exist in the database and the ForeignKey check complains.
Has anybody got an explanation? Shouldn't the id be created when persisting or merging the contract instance insttead?