--

Yes I mention in the "Which design is better?" section about the tradeoffs of both choices. Depending on the use case, the second choice might be preferable. Eg with Order and LineItems, you almost always want to load both together and delete them together. This is where Aggregate pattern is useful to pick amongst the choices based on business needs.

The "getReferenceById" is not enough in the second case because we need the Post entity to be loaded in the persistence context (as we intend to update it) instead of just a proxy.

The "getReferenceById" is useful in the specific scenario of bidirectional references described in the original blog. With aggregate pattern, the scenario can be avoided altogether. Spring Data is built around the DDD tactical patterns, not thinking about those patterns will likely result in misuse.

--

--

Abhinav Sonkar
Abhinav Sonkar

No responses yet