Hibernate: Encountered a duplicated sql alias [] during auto-discovery of a native-sq

Hibernate: Encountered a duplicated sql alias [] during auto-discovery of a native-sq

查询sql为:

StringBuffer sql = new StringBuffer();
        sql.append("SELECT a.id,a.teacher_name,a.user_code,r.id AS competitionId,r.competition_name,t.group_id,t.group_name");
        sql.append(" FROM app_teacher a");
        sql.append("  LEFT JOIN competition_record_teacher t");
        sql.append("  ON a.user_code = t.mobile");
        sql.append("  LEFT JOIN competition_record r");
        sql.append("     ON t.competition_id = r.id");
        sql.append(" WHERE r.status = 0 AND a.user_code=?");
        Query query =  session().createSQLQuery(sql.toString());

select 后的字段没有加别名...... 导致2个相同的id 加别名即可。

qrcode_for_gh_bf7a27ade681_258.jpg

作者: 小柒

出处: https://blog.52itstyle.com

分享是快乐的,也见证了个人成长历程,文章大多都是工作经验总结以及平时学习积累,基于自身认知不足之处在所难免,也请大家指正,共同进步。

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 如有问题, 可邮件(345849402@qq.com)咨询。