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.
i want update parent if i directly find id , change attribute , save.
i know hibernate has no info when getparent() child got child , not find id , makes update parent.
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
Post a Comment