java - @PreUpdate doesn't save parent object when it's updated -


i have 2 entities relation 1 many. parent can have several child entity instances. added field parent stores date of children modifications(childrenlastmodifieddate). maintain that, added method:

@prepersist @preupdate @preremove private void handle() {     parent.setchildrenlastmodifieddate(now()); } 

here problem. it's not invoke when child saved. locally(mac os), works expected, 3 types of changes tracked , saved parent entity. however, on server(linux) works for:

  • @prepersist
  • @preremove

even though, preupdate invoked, changes not saved. have tried add direct repository call save parent. result same. nothing saved on update, saved on remove or persist. tried make change in additional transaction , worked, it's resource consuming. also, can see had similar experience:

jpa/hibernate preupdate doesn't update parent object

however, there nothing on how handle problem itself. question is: there way guarantee using of annotations work , perform additional updates of dependent entities? if it's not, best way handle such logic? update required on each change children. if saved cascade.

it seems issue @preupdate only.

my personal opinion your entity not updated if @preupdate not called. can check easily. recommend use optimistic lock (just use version field following hibernate doc) or auditing entities need check update activity. if update processed detect if @preupdate activity processed or not. after tests you'll detect issue.

p.s.

i've never checked behavior if @preupdate used @ same time entity , subscribed @entitylisteners entity. me conflict in case. not sure if have both of annotations, please check complex , separate behavior (who knows, may hibernate developers decided impossible case, because not need @preupdate handlers in entity if declared in entity listener implementation. if you'll check it, please let me know in comment).


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -