在另一个实体内使用DAO和实体参考中使用DAO是一个架构问题吗?

发布于 2025-02-08 06:36:25 字数 2078 浏览 1 评论 0原文

我正在使用MVC-Architecture(JSP+Servlets+MySql& amp; no Orm-frameWorks)在Java Web应用程序上工作,并且我有下一个数据库:数据库

我想在我的JSP视图上创建JSTL Core lib的表格,看起来像:

接收式ServiceName接收年份YourMaster状态DateTime
1Haircut1 Haircut 20 UsdPeter AndersonNew17.06.2022 10:00,

所以我决定进行下一个实体和DAO建筑:

这是我在数据库中可接待的实体。

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
}

我担心接收中包含另一个实体(服务,用户),这使我在另一个dao中使用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;
}

所以我有几个问题:

  1. 在另一个实体中使用实体对象参考是一个好习惯吗?
  2. 在另一个dao中使用dao还是不良的做法是有意义的吗?
  3. 如果这是一个很大的问题,请告诉我如何解决这个问题。

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:

ReceptionIDServiceNameReceptionCostYourMasterStatusDateTime
1Haircut20 USDPeter AndersonNew17.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:

  1. Is it good practice to use entity-object reference in another entity?
  2. Does it make sense to use DAO inside another DAO or maybe it is a bad practice?
  3. If it is a very big problem, tell me how can i solve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文