如何使用完全连接在hibernate中编写子查询

时间:2013-08-13 12:09:18

标签: java hibernate

我是hibernate的新手,我想在hibernate中转换下面的查询

Select a.* from ((select b.* from B b) full 
    join (select c.* from C c) on b.id=c.id) a where a.somecoulumn=condition

1 个答案:

答案 0 :(得分:0)

使用createSqlQuery而不是createQuery ..

    public List getList(String sql) {
        Session session = factory.openSession();
        Transaction tx = null;
        List list = null;
        try {
            tx = session.beginTransaction();
            list = session.createSQLQuery(sql).list();
            tx.commit();
            return list;
        } catch (HibernateException e) {
            if (tx != null) {
                tx.rollback();
            }
            e.printStackTrace();
            return null;
        } finally {
            session.close();
        }
    }