Question

My model:

 public class Father {
  Set<Son> sons = new HashSet<Son>();
  String name = null;
  Date lastSonModifyDate = null;
  // ... other fields and setters/getters
 }
 public class Son {
  Father father = null;
  String name = null;
  Date lastModifyDate = null;
  // ... other fields and setters/getters
 }

Use case:

  1. There is in DB a Father object with a Son object associated (bidir).
  2. Load from DB father.
  3. Update name field for father.
  4. Update name field for son.
  5. Persist father.

My interceptor first detects father updates (onFlushDirty). Then executes the onFlushDirty for the son. In this case, I update son.lastModifyDate and also father.lastSonModifyDate.

When execution ends, all updates are persisted except father.lastSonModifyDate. I think this is because father is in session and has been updated before son, so this entity overrides the changes done in onFlushDirty method for the son entity.

How could I achieve my mark (set father's lastSonModifyDate from son interceptor)?

Thanks.

Was it helpful?

Solution

You can't. onFlushDirty() is invoked for collection elements after it has been invoked for owner and update action (if any) has already been scheduled.

Is there any reason why you can't do all of the above in your DAO instead of relying on interceptors? Or on the database level (mapping both lastModifyDate properties as generated)?

OTHER TIPS

you need to override onCollectionUpdate for entities that has cascading option. this is called before its being scheduled.

cheers~

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top