【发布时间】:2016-02-12 08:09:30
【问题描述】:
我正在尝试做的是在 Bean 属性和 DAO 之间建立一种惰性关系。
这是我的代码:
豆类文章
public class Article {
private Long id;
private Product product;
private Attribut attribut;
private String name;
private Article ParentArticle;
\\ getters and setters
}
将文章映射到 Bean 的 DAO
private Article map(ResultSet resultSet) throws SQLException {
Article article = new Article();
\\set the id of the Article
article.setId(resultSet.getLong("id"));
\\get the DAO of each article Bean attribute
ProductDao productDao = daoFactory.getProductDao();
ArticleDao articleDao = daoFactory.getArticleDao();
AttributsDao attributsDao = daoFactory.getAttributDao();`
\\set the product of the article by searching the product with his DAO
article.setProduct(productDao.find(resultSet.getLong("idProduct")));
\\set the Attribut of the article by searching the attribute with his DAO
article.setAttribut(attributsFonctionsDao.trouver(resultSet.getLong("idAttribut")));
\\set the designation of the article article.setDesignation(resultSet.getString("designationArticle"));
\\set the Parent Article by searching the article with his DAO
article.setParentArticle(articleDao.trouver(resultSet.getLong("idArticleParent")));
return article;
}
所以我要问的是是否有办法映射文章对象属性,所以这里的属性产品、属性和父文章只有它们的 id 而不是对所有对象收费。我知道 Hibernate 可以提供帮助,但我想在没有 ORM 的情况下手动设置它。
【问题讨论】:
标签: java jakarta-ee mapping dao