-
-
Notifications
You must be signed in to change notification settings - Fork 964
7.0.0-RC2 BUG FIX - @AutoTimestamp Mongo Persistence #15122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7.0.0-RC2 BUG FIX - @AutoTimestamp Mongo Persistence #15122
Conversation
9391558
to
bc1808a
Compare
In SummaryAll this does is make @AutoTimestamp properties dirty if there are changes so they will be persisted. It doesn't affect anything else. You can verify everything working on both hibernate and mongo in just 3 commands. Publish fix to mavenLocal()
Run fix on port 8081 for mongo and 8082 for hibernate in 2 command
http://localhost:8081/user/create |
} | ||
else { | ||
// schedule lastUpdated if necessary | ||
if (entity.getPropertyByName(GormProperties.LAST_UPDATED) != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you just trying to minimize updates by removing this statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdaugherty yes, updates should be uniform in 1 location.
Set<String> props = getLastUpdatedPropertyNames(entity.getName()); | ||
if (props != null) { | ||
Object entityObject = ea.getEntity(); | ||
boolean isDirtyCheckable = entityObject instanceof DirtyCheckable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instanceof is incompatible with Hibernate Proxies
Class<?> lastUpdateType = ea.getPropertyType(prop); | ||
Object timestamp = timestampProvider.createTimestamp(lastUpdateType); | ||
ea.setProperty(prop, timestamp); | ||
// Mark property as dirty for datastores that use dirty checking (e.g., MongoDB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this is a mongo specific, but hibernate does have dirty checking and works. What makes hibernate different here?
storeTimestampAvailability(entitiesWithLastUpdated, persistentEntity, property); | ||
} else { | ||
storeTimestampAvailability(entitiesWithDateCreated, persistentEntity, property); | ||
Field field = ReflectionUtils.findField(persistentEntity.getJavaClass(), property.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're trying to target a bug fix, why switch to a different method of resolution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdaugherty because it is does exactly same thing.
I think this is a possible candidate for 7.0.1. |
This really needs to go out in 7.0.0 as it is currently completely broken
This is the isolated part of PR #15118 that fixes #15120
All it does is mark properties annotated with @AutoTimestamp dirty so they are guaranteed to be saved during updates.
To see existing non behavior:
Create and Edit to see modified not updated after edit save.
http://localhost:8080/user/create
http://localhost:8080/user/edit/1
The checkout grails-core fix branch and publish it to mavenLocal
You can verify fix on MongoDb
http://localhost:8081/user/create
http://localhost:8081/user/edit/1
You can verify fix also works on Hibernate
http://localhost:8082/user/create
http://localhost:8082/user/edit/1