I typical hibernate pojo class looks
public class User {
private String username;
.
.
.
private Address address;
}
public classs Address {
private String line1
.
.
.
private User user;
}
i.e 1-1 dependency means one user has one address and vise verse one address belong to one user.
Now this dependency expressed through composition is very difficult to modularize.
As when project gets big, I would like to use multi-module dependency of maven and split the pojos/ domain objects in different modules/ projects.
But this causes circular dependency and we do like wise all the classes are inter-related.
And because we are using them in orm of hibernate we need them to be strictly composite of each other.
Any suggestion where we can split these in independent 1. user module 2. address module
Allowing me to use only one which is required.
I read through some post which suggests to use templates/ interfaces but I doubt it will work with hibernate behind the scenes.
Well, I found the answer to change the dependency from not being bi-directional but make it uni-directional wherever possible.
Like in above case -
We need to access address from user, to show user's address but we rarely have a business scenario where we need to get user from address.
i.e Have address pogo to hold user.id as integer instead of having user object inside Address
Address {
User user
...
....
}
Adress {
Integer userid
....
....
}
now user module depends on address but address does not depend on user.