For my application where authors write articles I implemented an autoSave mechanism. This update data in DB periodically. As I have some problems with the locking behavior (version field in each table is used for this) I need to overwrite a dirty entry.
Is there some “flag” or command for saving to DB and ignoring hibernate lock?
Will it be an alternative to get the data from DB again if it is dirty and after that save again? As we now have a new version and locking is over it should be no problem to save.
pseudo code (not tested):
if (article.isDirty()) {
article.get(params.id)
}
article.bindData(params)
article.save()
Take a look at the refresh() method for domain classes: http://www.grails.org/doc/latest/ref/Domain%20Classes/refresh.html
Note that there are caveats, so the best thing is to pull the latest version of your domain object and then programmatically merge the data: http://www.grails.org/doc/latest/guide/single.html#5.3.5%20Pessimistic%20and%20Optimistic%20Locking