I am working on java web application with MVC-architecture (JSP+SERVLETS+MYSQL && NO ORM-FRAMEWORKS) and I have next database: database.
I wanted to create table by JSTL core lib on my JSP-view that looks like that:
ReceptionID | ServiceName | ReceptionCost | YourMaster | Status | DateTime |
---|---|---|---|---|---|
1 | Haircut | 20 USD | Peter Anderson | New | 17.06.2022 10:00 |
So i decided to make next Entity and DAO architecture:
This is my Entity for ReceptionTable in database.
public class Reception extends BaseEntity {
private Service service;
private User master;
private User client;
private int cost;
private LocalDateTime receptionDateTime;
private Status status;
// getters setters
}
I am worried about Reception contains another Entities (Service, User) and it makes me to use DAO inside another DAO:
public class ReceptionDAO implements GenericDAO<Reception> {
public Reception mapReception(ResultSet resultSet) throws SQLException, DaoException {
Reception reception = new Reception();
long receptionId = resultSet.getLong("id");
long serviceId = resultSet.getLong("service_id");
long masterId = resultSet.getLong("master_id");
long clientId = resultSet.getLong("client_id");
int cost = resultSet.getInt("cost");
LocalDateTime dateTime =resultSet.getTimestamp("reception_date_time").toLocalDateTime();
int statusId = resultSet.getInt("status_id");
UserDAO userDAO = new UserDAO();
ServiceDAO serviceDAO = new ServiceDAO();
reception.setId(receptionId);
reception.setService(serviceDAO.findById(serviceId));
reception.setMaster(userDAO.findById(masterId));
reception.setClient(userDAO.findById(clientId));
reception.setCost(cost);
reception.setReceptionDateTime(dateTime);
reception.setStatus(Status.getStatus(statusId));
return reception;
}
So i have a several questions:
- Is it good practice to use entity-object reference in another entity?
- Does it make sense to use DAO inside another DAO or maybe it is a bad practice?
- If it is a very big problem, tell me how can i solve this.