zoukankan      html  css  js  c++  java
  • 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适合于外表小而内表大的情况。

  • 相关阅读:
    Java 和 DynamoDB
    关于Mongodb的全面总结
    utf8mb4 使用注意
    mysql 事务隔离讲的比较好的文章收藏。
    [mysql] 常用命令总结
    [JTA] Java事务api
    [Hibernate] Hibernate 参数设置一览表(转)
    Spring配置sessionFactory的几种常用方式
    [前端] org.apache.jasper.JasperException 页面有空引用
    [Hibernate] JPA与Hibernate的优缺点
  • 原文地址:https://www.cnblogs.com/king-/p/6594433.html
Copyright © 2011-2022 走看看