解决 Cause: org.postgresql.util.PSQLException: ERROR: column reference "flag" is ambiguous

在使用postgresql进行开发时出现如下错误

### Cause: org.postgresql.util.PSQLException: ERROR: column reference "flag" is ambiguous
  Position: 580
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column reference "flag" is ambiguous
  Position: 580
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:364)
    at $Proxy10.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159)
    at net.suntec.dynabiz.service.msgservice.dao.impl.MsgContentDAOImpl.findOne(MsgContentDAOImpl.java:72)
    at net.suntec.dynabiz.service.msgservice.dao.impl.MsgContentDAOImpl.findOne(MsgContentDAOImpl.java:1)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy13.findOne(Unknown Source)

通过字面意思可以知道Cause: org.postgresql.util.PSQLException: ERROR: column reference "flag" is ambiguous

flag 这个字段是模糊不清的

通过调查sql发现 我使用了多表联查 flag字段在两个表中都存在,没有给flag添加表的别名

原来写法

SELECT mc.id, mc.title, mc.body  FROM tb_book as mc ,tb_manager as mm    WHERE  mc.id= mm.content_id    AND flag = '0'

需要修改成

SELECT mc.id, mc.title, mc.body  FROM tb_book as mc ,tb_manager as mm    WHERE  mc.id= mm.content_id    AND mc.flag = '0'
来源://作者:/更新时间:2014-06-28
相关文章

最新文章

新热推荐

文章排行