I have several modules in my Spring Boot application (broken with DDD in mind), which would sometimes need to depend on another module not because of logic, but because the entities are related. For example, User is an entity needed in other modules, now I do not want my modules to be coupled except to core module.
I have experience in Django and Django solved this issue by, for example, using an interface function called get_user_model (which the same logic could be applied for other models). Now in Spring, if it was a service or some other class, we could use DI, but I could not figure out how DI would be applied here and do not find anything else to decouple the use of entities and their repositories (as I use hibernate with JPA).
user module:
@Entity
public class UserEntity implements Serializable {
@Id
@GeneratedValue
private Long id;
private String username;
private String password;
private String roles;
private boolean isActive;
private boolean isStaff;
private boolean isSuperUser;
}
notification module:
@Entity
@Table(name = "notification")
public class NotificationEntity {
@Id
@GeneratedValue
@Setter
@Getter
private Long id;
@ManyToOne()
@JoinColumn(name = "username")
private UserEntity user; // want this to not reference UserEntity directly, to decouple this module from user module
}
Is there a way to reference other entities and yet maintain decoupling?
Useris an entity needed in other modules, now I do not want my modules to be coupled" - this is contradictory