hibernate
-- select 后面没有加别名
Encountered a duplicated sql alias [id] during auto-discovery of a native-sql query
-- 看看数据库是否没有这个column
could not extract ResultSet
=====================================================================================================
session.createQuery(queryStr).list(); //hql
session.createSQLQuery(queryStr).list(); //普通sql
========================================================================
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!
正确写法:
@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适合于外表小而内表大的情况。