Hibernate - How to persist a new item in a Collection without loading the entire Collection

前端 未结 4 1399
悲哀的现实
悲哀的现实 2020-12-05 14:20

I have a collection in my model that contains a set of \'previous versions\' of my root domain object. The previous versions are therefore \'immutable\' and we will never wa

4条回答
  •  爱一瞬间的悲伤
    2020-12-05 15:00

    If I understand well your need:

    • you have an in-memory add-only collection of immutable objects
    • how to add an item to that collection without initializing the entire collection (in the current Session)?

    Did you consider maintaining your collection disconnected?

    • Load it once when the application starts
    • Adding an element would mean two operations, done by a single service in only one place:
      • save the element (fast database operation, no cascading is done to the parent)
      • add the element to the existing disconnected collection (no database operation)

提交回复
热议问题