0

我想将下面的查询转换为 hql 以返回我,List<Article>因为使用 createSqlQuery 是不可能的,我必须手动转换结果:
这是 sql 查询:

Query query = getSessionFactory().getCurrentSession().createSQLQuery(
                 "select * 
                  from article 
                  where articleID in (select articleID 
                                      from article_depot 
                                      where depotID = "+depotID+")"
              );

先感谢您

4

1 回答 1

2

假设您在和之间有OneToMany关系(一个仓库包含多篇文章),如果已正确映射,则查询将是:article_depotarticle

Query query = getSessionFactory().getCurrentSession().createQuery("SELECT d.article from article_depot d where d.depotId = :depotId");
query.setParameter("depotId", depotId);
List<article> resultList = query.getResultList();
于 2013-04-05T08:31:06.753 回答