23 Mai 2012

grails hibernate "problems"

def user = User.get( id ) // also .load or .read
user.aProperty = "newValue"

At this point you have to expect, haha thats new text in here that "newValue" is persisted to hibernate session. In other words domain interceptors like beforeUpdate() are not working as intended. See the following:

user.save()
this save call (even with flush: true) is "needless". if there is defined a beforeUpdate interceptor like:

beforeUpdate() {
  if ( aProperty.isDirty() ) {
    doSomething()
  }
}
doSomething is never called! beforeUpdate() ask the hibernate session if there are any changes :) better to flush session with

def user = User.get( id ).save( flush: true )

Keine Kommentare: