JPA Entities and module boundaries #681
Unanswered
luciano-fiandesio
asked this question in
Q&A
Replies: 1 comment
-
Hello, If User and Document are separate aggregates, references between them should be managed carefully to maintain aggregate boundaries and integrity. Here is my take on the subject for Managing Relationships Between Aggregates :
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm introducing Modulith in an existing Spring Boot monolith to address issues with broken boundaries and circular dependencies. One of the architectural challenges I'm encountering involves JPA relationships. Here's a simplified example:
There are 2 modules:
users
anddocuments
. TheUser
JPA entity referencesDocument
(@OneToMany
). This setup breaks the boundary between the moduleuser
anddocuments
, becauseDocument.java
is leaking into theuser
module.I can see three possible solutions:
jpa
). This is obviously a very bad idea!For example, the users module would be structured as follows:
To me, the third approach is the one that makes more sense, even at the cost of some code duplication.
Are there more design solutions I am missing? I'd appreciate any feedback or suggestions on this approach.
Beta Was this translation helpful? Give feedback.
All reactions