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?
Any answers are very welcome.
thanks for your time.
posted 2 years ago
If possible, can you post the code for Contract and AttachedFile.
and the code where/how Contract and AttachedFile are created and persisted.