When updating an derived entity containing several field, not all changed fields will be updated
Having a base entity containing two fields named *checksum* and *variantName* and a derived entity containing one field named *fileSize*.
Create an database entry,
{noformat}FileVersion version = new FileVersion(); version.setId("1"); version.setFileSize(100L); version.setCheckSumMD5("ABCDEF"); version.setVariantName("A");{noformat}
change all fields of the existing database entry (see testcase *testWithDynamicUpdate*)
{noformat}version.setCheckSumMD5("XXXXXXXX"); version.setVariantName("B"); version.setFileSize(200L);{noformat}
The following update statement will be created
{noformat}Hibernate: update Versionen set CHECKSUM=?, FILESIZE=? where VERS_NUMMER=?{noformat}
Only *checksum* and *fileSize* will be updated, but not the field *variantName*.
Problem occurs in file *AbstractEntityPersister* in function *resolveDirtyAttributeIndexes*. The dirty fields will be sorted bei name
{noformat}Arrays.sort( attributeNames ); attributeName = {checkSum, fileSize, variantName}{noformat}
In the for loop the fields in *attributeNames* will be compared to the array *attributeMappings*, which contains the mapping informations according to the annotations.
*attributeMappings* has the following order:
{noformat}attributeMappings = { AbstarctVersion AbstractVersion .checksum, AbstractVersion.variantName, FileVersion.fileSize}{noformat}
The for loop does only recognize the fields *checksum* and *fileSize. variantName* will not be processed.
A sample project with test case can be found [here|https://github.com/HoBa1975/hibernate-mapping] |
|