hibernate

-- select  後面沒有加別名java

Encountered a duplicated sql alias [id] during auto-discovery of a native-sql querynode

-- 看看數據庫是否沒有這個columnsql

could not extract ResultSet數據庫

=====================================================================================================session

session.createQuery(queryStr).list();  //hql
session.createSQLQuery(queryStr).list();  //普通sqlide

========================================================================spa

hibernate 左鏈接:hibernate

@Test
    public void testLetfJion() {
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();
        String queryStr = "select stu from com.bjsxt.hibernate.Student as stu left join com.bjsxt.hibernate.Teacher as te on stu.id = te.id";
        session.createQuery(queryStr).list();
        session.getTransaction().commit();
    }

報錯:java.lang.IllegalStateException: DOT node with no left-hand-side!code

正確寫法:blog

    @Test
    public void testLetfJion() {
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();
        String queryStr = "select stu from com.bjsxt.hibernate.Student as stu ,com.bjsxt.hibernate.Teacher as te where stu.id = te.id";
        session.createQuery(queryStr).list();
        session.getTransaction().commit();
    }

============================================================================================

IN適合於外表大而內表小的狀況;EXISTS適合於外表小而內表大的狀況。

相關文章
相關標籤/搜索