Search code examples
javaspringassociationsbidirectional

Java code design bidirectional association


This is a question about application code design. Here is my situation:
I have a db table named Report which represents the amount of time of work of a user during a given month. I have a DAO to deal with database and a @Service which encapsulates dao's methods and do more stuff with reports.

In addition, I have a table Target, to assign goals to the users about their activities (goals can be monthly or yearly). I have again a DAO and a @Service to use these entities.

My question is about design, because i have a bidirectional association between the two services, especially for the following processes:

  • The Report service needs to update the target service when a report is added, modified or deleted..
  • The target service needs the report service when we need to calculate the progression of a Target

I'm refactoring my application and seeing the two beans beans who need each other makes me feel this is not so good...
Is there a way to design properly this situation (I mean the association between my two services) or should I stay with the bidirectional association?


Solution

  • Finally, I solved my problem by making some changes in my ReportDAO and by calling it in my TargetService. By doing this, I could remove bidirectional association between my two services and have only an unidirectional association.