HI, I'm trying to understand the behaviour of cascade
This is my mapping for a 'File' object, which can have many 'Field' objects
Code:
@OneToMany(fetch=FetchType.LAZY)
@JoinTable(
name="BULK_UPLOAD_FILE_TYPE_FIELD",
joinColumns = @JoinColumn(name="BULK_UPLOAD_FILE_TYPE_ID", referencedColumnName="BULK_UPLOAD_FILE_TYPE_ID"),
inverseJoinColumns = @JoinColumn(name="BULK_UPLOAD_FILE_FIELD_ID", referencedColumnName="BULK_UPLOAD_FILE_FIELD_ID")
)
private List<BulkUploadFileField> fields = new ArrayList<BulkUploadFileField>();
Now, the File object does have a collection of Fields in the database, but in my code, I just want to save the details of the File object in one case (when the user has modified some values at the front end)
So from the front end, I pass in parameters and reconstruct the File parent object MINUS the Fields that are associated with it (File.getFields() would return null)
Since I have no cascade settings on my OneToMany, I was expecting the 'merge' operation to persist the new values of File object, but leave the collection alone.
However, it deletes all the Field associations in my DB join table (I can see the delete statements that Hibernate generates)
I only want Hibernate to delete/update etc my Field associations when I explicitly tell it - what am I doing wrong?
Thanks!
PS I can get around this by loading a fresh copy of the File object from the database (complete with it's populated Field collection) and then overwriting the parent's values with what the user has supplied, but the extra read operation seems inefficient