Details
-
Type:
Sub-task
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0
-
Fix Version/s: 1.1-beta1
-
Component/s: Controllers
-
Labels:None
Description
Currently the symantics of Hibernate are such that changes to the db are automatically performed and committed if an loaded Object is modified. So the User Object changes to the Database are performed when groovy execute "u.properties = params". So the Object is modified, but u.save() was never called.
Seems that the loaded Object is bound to the Hibernate Session, so Hibernate checks the Object for changes.
Unable to find source-code formatter for language: groovy. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
def u = User.get(1) u.properties = params // validation fails here // Everything below is senseless for the "u" Object, because Changes are already written to the Database if(u.save()) { } else { // handle errors }
I think this is very critical, because the Grails validation won't work correct.
So a validation Error is displayed, but the Object has been modified ?!
Is there a method to evict the Object from the Hibernate Session? (u.evict() doesn't work).
You can use discard(). We used to evict, but it causes problems as the associations might still be in the session, now we set the session flush mode to manual on a validation error. So the changes don't get flushed to the db on a validation error, you can still force them to be using save(flush:true) to recover from a validation error programmatically, but as far as I'm concerned this issue is not an issue