欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Column 'status' in where clause is ambiguous

程序员文章站 2022-06-30 16:36:12
...

当你需要联表查询时,若两个表都有相同的字段是,需要为相同字段加上表别名
例如:相同字段:status ==》t.status 即可解决。
该异常出现的原因筛选联表查询,由于status直接封装到查询的实体中从而引发异常。可以让status前面添加表名重新拼装sql进行联表查询
异常如下:
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [
select count(*) from (
    select info0_.id as id49_, info0_.infotype as infotype49_, info0_.title as title49_, info0_.subTitle as subTitle49_, info0_.content as content49_,
    info0_.type as type49_, info0_.createtime as createtime49_, info0_.publishtime as publisht8_49_, info0_.lastupdatetime as lastupda9_49_,
    info0_.views as views49_, info0_.lastViewTime as lastVie11_49_, info0_.remark as remark49_, info0_.icon as icon49_, info0_.summary as summary49_,
    info0_.source as source49_, info0_.ispoint as ispoint49_, info0_.important as important49_, info0_.support as support49_, info0_.oppose as oppose49_,
    info0_.status as status49_, info0_.sort as sort49_, info0_.sign as sign49_, info0_.keywords as keywords49_, info0_.iconintroduce as iconint24_49_,
    info0_.layouttype as layouttype49_, info0_.isreview as isreview49_, info0_.resourcestype as resourc27_49_, info0_.temp1 as temp28_49_,
    info0_.temp3 as temp29_49_, info0_.temp2 as temp30_49_, info0_.USERID as USERID49_, info0_.MEMBERID as MEMBERID49_ from T_INFO info0_,
    T_INFOANDCLASS infoandcla1_
    where info0_.id=infoandcla1_.infoid and infoandcla1_.classid=4 and status=? and resourcestype=? and (content like ?) and infotype=? and (source like ?) )  as a]
    ; Column 'status' in where clause is ambiguous;
    nested exception is com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'status' in where clause is ambiguous

相关标签: HQL 联表查询