Editing an object in AfterInsert / AfterUpdate

I have a domain object that contains calculation results based on parameters that are properties of the same domain object. I would like to make sure that user parameters change at any time, it recounts and is automatically saved in the database.

I am trying to do this using afterInsert (to make sure the calculation is correct first) and afterUpdate.

However, since my calculation is trying to change the object itself, it does not work - it throws various exceptions in sleep mode.

I tried putting the afterUpdate code in a transaction, but that didn't help. I'm afraid that I get into round problems with addiction.

The exception that I am getting now is:

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

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

+5
source share
2 answers

Are you using 1.2.0 +?

If you are, you can use .withNewSession in closing events, which should avoid hub chaos.

amuses

Lee

+3
source

Is there any reason against using beforeInsertand beforeUpdateinstead of afterInsertand afterUpdate?

If not, switching to event handlers before*should fix your problem

+2
source

All Articles