Strategies for dealing with Circular references caused by JPA relationships?
- by ams
I am trying to partition my application into modules by features packaged into separate jars such as feature-a.jar, feature-b.jar, ... etc.
Individual feature jars such as feature-a.jar should contain all the code for a feature a including jpa entities, business logic, rest apis, unit tests, integration test ... etc.
The problem I am running into is that bi-directional relationships between JPA entities cause circular references between the jar files. For example Customer entity should be in customer.jar and the Order should be in order.jar but Customer references order and order references customer making it hard to split them into separate jars / eclipse projects.
Options I see for dealing with the circular dependencies in JPA entities:
Option 1: Put all the entities into one jar / one project
Option 2: Don't map certain bi-directianl relationships to avoid circular dependencies across projects.
Questions:
What rules / principles have you used to decide when to do bi-directional mapping vs. not?
Have you been able to break jpa entities into their own projects / jar by features if so how did you avoid the circular dependencies issues?