Strategies for dealing with Circular references caused by JPA relationships?
Posted
by
ams
on Stack Overflow
See other posts from Stack Overflow
or by ams
Published on 2012-12-08T17:01:35Z
Indexed on
2012/12/08
17:03 UTC
Read the original article
Hit count: 234
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?
© Stack Overflow or respective owner