Hibernate versioning parent entity

前端 未结 4 1282
暖寄归人
暖寄归人 2021-01-13 17:51

Consider two entities Parent and Child.

  • Child is part of Parent\'s transient collection
  • Child has a ManyToOne mapping to parent with FetchType.LAZY
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 18:55

    i don't think you can force hibernate to increase a version number for a non-changed object, because it will just not do any db UPDATE query if nothing has changed (for obvious reasons).

    you could do a nasty hack like adding a new field to the object and incrementing that manually, but personally that seems to be a waste of time and resources. i'd go with your explicit locking solution since that seems to give you what you want, without unnecessary hackery.

提交回复
热议问题