java - Disable update to many to one entity in hibernate -


i have parent , child entity. child has manytoone annotation reference parent. use case when load child findbyid , parent out using getter. if update parent, able save parent. not want parent updatable pulled out child.

  1. i want update parent if i directly find id , change attribute , save.

  2. i know hibernate has no info when getparent() child got child , not find id , makes update parent.

  3. i tried immutable annotation on manytoone on parent not prevent update fired.

is there way can make parent pulled out child non-updatable?

feel free ask clarifications.

the problem experiencing, in fact belongs hibernate session. has nothing cascading. because session designed unit-of-work us.

whenever access object 1) id or 2) reference, object (from moment) "cached" in session. 1 instance shared accross handling during session life-time.

so, once, parent loaded session, , amending anyhow, , later session flushed - changes parent persisted.

you can call session.evict(parent) explicitly, avoid changes propagation during flush.

but seems me bit weird, changing parent (accidently...maybe) while working child , not willing store these changes. other words, maybe solution change approach.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -