I have an application that has the following java files:
Services:
AccountService.java
UserService.java
MessageService.java
DAOs:
AccountDAO.java
UserDAO.java
MessageDAO.java
Tables:
ACCOUNTS
USERS
MESSAGES
In MessageService.java
, I have a function newMessage()
that has to query data from all the 3 tables.
(1) According to Spring's decoupling standards, this is how the calls should be made:
AccountDAO.java -- ACCOUNTS
/
MessageService.java -- MessageDAO.java -- MESSAGES
\
UserDAO.java -- USERS
But the problem is, this approach makes 3 DB calls.
(2) For better Performance, I would do:
MessageService.java -- MessageDAO.java -- Join ACCOUNTS, MESSAGES and USERS
But this way, it's tightly coupled and if there's a change in USERS table, I'll have to change MessageDAO.java (and all other DAOs that I have, that use the USERS table) too. That is really bad, since (in the non-hypothetical) we have a LOT of DAOs
Which approach is considered a better practice? Or is there another approach that I'm missing?