Modifying object in AfterInsert / AfterUpdate

Posted by Jean Barmash on Stack Overflow See other posts from Stack Overflow or by Jean Barmash
Published on 2010-03-04T20:42:46Z Indexed on 2010/06/02 6:03 UTC
Read the original article Hit count: 184

Filed under:
|

I have a domain object that holds results of a calculation based on parameters that are properties of the same domain object. I'd like to make sure that any time parameters get changed by the user, it recalculates and gets saved properly into the database.

I am trying to do that with afterInsert (to make sure calculation is correct in the first place), and afterUpdate.

However, since my calculation is trying to modify the object itself, it's not working - throwing various hibernate exceptions.

I tried to put the afterUpdate code into a transaction, but that didn't help. I am afraid I am getting into a circular dependency issues here.

The exception I am getting right now is:

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [esc.scorecard.PropertyScorecard#27]

Are the GORM events designed for simpler use cases? I am tempted to conclude that modifying the object you are in the middle of saving is not the way to go.

© Stack Overflow or respective owner

Related posts about grails

Related posts about gorm