简单sql查询到hibernate查询

toiithl6  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(284)

这是我的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表has=>icerikid yazi\u kategori has=>icerikid,kategoriid kategori表has=>kategoriid

mklgxw1f

mklgxw1f1#

您的标准如下:

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()

相关问题