简单的Sql查询到Hibernate查询

时间:2017-10-31 12:59:06

标签: java mysql database hibernate

这是我的SQL查询,我怎么能在hibernate上写这个?有一种“多对多”的关系。

SELECT * 
FROM icerik AS i 
LEFT JOIN yazi_kategori AS yk 
ON i.YAZI_ID = yk.YAZI_ID 
LEFT JOIN kategori AS k ON yk.KATEGORI_ID = k.KATEGORI_ID
WHERE yk.KATEGORI_ID = 1;
  

icerik table has => icerikid yazi_kategori has => icerikid,kategoriid   kategori表有=> kategoriid

1 个答案:

答案 0 :(得分:0)

您的标准如下:

 Criteria criteria = session.createCriteria(Icerik.class, "i");
    criteria.createAlias('i.yazi_kategori', 'yk', CriteriaSpecification.LEFT_JOIN);
    criteria.createAlias('i.kategori', 'k', CriteriaSpecification.LEFT_JOIN);
    criteria.add(Restrictions.eq('i.KATEGORI_ID', 1));
    criteria.list()