-
Notifications
You must be signed in to change notification settings - Fork 31
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
Can't refresh domain class instance from the database in statefull mode #147
Comments
Any update here? |
Hi. Unfortunately no. I managed to fix that project by managing concurrency in Java itself. My Stack Overflow post was deleted for some reason. I can paste it here if you want more details. |
Thanks, @yagotlima. Please paste it here and share the link as well. |
My original Stack Overflow question was: How to refresh object from database unsing GORM for MongoDB?I have a Grails application using mongoDB that runs a long piece of code that updates a domain class at the end. Since this piece of code runs concurrently I'm gatting a lot of To avoid that I decide to do as following:
Unfortunatelly the I also tried the following:
But looks like there is some sort of session that returns the same object like Hibernate's L1 cache would. Is there a way to refresh this instance? PS: I'm aware I can switch the class to stateless mode but that would require a huge refactor and stateful mode is just better for my use case except for this piece of code. |
So far, the need of Vehicle vehicleInstance // some existing instance
Vehicle.withNewSession {
vehicleInstance = Vehicle.get(vehicleInstance.id)
} We further made this DRY in our base abstract test file by adding a method- GormEntity refreshInstance(GormEntity instance) {
// Flushing to get persist it to DB immediately
instance.save(flush: true)
UserOrAnyDomain.withNewSession {
return instance.class.get(instance.id)
}
} and then calling directly- Vehicle vehicleInstance // some existing instance
vehicleInstance = refreshInstance(vehicleInstance) |
I think |
Thanks, @yagotlima. I would like to keep this issue open so that the GORM team can implement it natively. |
@sagrawal31 sorry for that |
I'm creating this issue after failing to find a solution from Stackoverflow.
Since the
refresh
method is not implemented on Gorm for Mongo and the methodget(id)
would return the same cached instance, is it possible to refresh a domain class instance from the database?The text was updated successfully, but these errors were encountered: