Holger Bach (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=642158a...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjhlNWZiMmY2...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16379?atlOrigin=eyJpIjoiMjhlNW...
) HHH-16379 (
https://hibernate.atlassian.net/browse/HHH-16379?atlOrigin=eyJpIjoiMjhlNW...
) @DynamicUpdate and 'enableDirtyTracking=true' leads to wrong update statement (
https://hibernate.atlassian.net/browse/HHH-16379?atlOrigin=eyJpIjoiMjhlNW...
)
Issue Type: Bug Affects Versions: 6.0.2, 6.1.7 Assignee: Unassigned Components:
hibernate-orm-modules Created: 27/Mar/2023 03:28 AM Environment: Java 17 Priority: Major
Reporter: Holger Bach (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=642158a...
)
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,
FileVersion version = new FileVersion();
version.setId("1");
version.setFileSize(100L);
version.setCheckSumMD5("ABCDEF");
version.setVariantName("A");
change all fields of the existing database entry (see testcase *testWithDynamicUpdate* )
version.setCheckSumMD5("XXXXXXXX");
version.setVariantName("B");
version.setFileSize(200L);
The following update statement will be created
Hibernate: update Versionen set CHECKSUM=?, FILESIZE=? where VERS_NUMMER=?
Only *checksum* and *fileSize* will be updated, but not the field *variantName*.
Problem occurs in file *AbstractEntityPersister* in function
*resolveDirtyAttributeIndexes*. ch
The dirty fields will be sorted bei name
Arrays.sort( attributeNames );
attributeName = {checkSum, fileSize, variantName}
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:
attributeMappings = {AbstarctVersion.checksum, AbstractVersion.variantName,
FileVersion.fileSize}
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 )
(
https://hibernate.atlassian.net/browse/HHH-16379#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16379#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100219- sha1:ac3e918 )