3

嗨,我有一个应该返回列表的方法,但我得到了查询数据库时出错。原因:com.microsoft.sqlserver.jdbc.SQLServerException:无效的对象名称“CATSTATUSPRINT”。, 错误可能存在于com/mapper/CatStatusPrintMapper.xml , 错误可能涉及defaultParameterMap , 设置参数时出错

这是我的映射器 CatStatusPrintMapper.xml:

<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="statusMapper">

     <select id="consultCatStatus" resultMap="catStatusMap">
        SELECT 
            C.ID_STATUS,
            C.NAME_STATUS, 
            C.DESC_STATUS,
            C.ACTIVE
        FROM CATSTATUSPRINT C
         WHERE C.ACTIVE = 1
        ORDER BY C.NAME_STATUS ASC
    </select>

     <select id="consultCatStatus2" resultMap="catStatusMap">
        SELECT 
            C.ID_STATUS,
            C.NAME_STATUS, 
            C.DESC_STATUS,
            C.ACTIVE
        FROM CATSTATUSPRINT C
         WHERE C.ACTIVE = 2
        ORDER BY C.NAME_STATUS ASC
    </select>    

    <resultMap id="catStatusMap" type="catStatus">
        <result column="ID_STATUS" property="idStatus"></result>
        <result column="NAME_STATUS" property="nameStatus"></result>
        <result column="DESC_STATUS" property="descStatus"></result>
        <result column="ACTIVE" property="active"></result>
    </resultMap>

</mapper>

这是我的实体 bean:

@Entity
@Table(name = "CatStatusPrint")
public class CatStatusPrintBean implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID_STATUS")
    private Integer idStatus;
    @Basic(optional = false)
    @Column(name = "NAME_STATUS")
    private String nameStatus;
    @Column(name = "DESC_STATUS")
    private String descStatus;
    @Basic(optional = false)
    @Column(name = "ACTIVE")
    private Integer active;

    public CatStatusPrintBean() {
    }

    public CatStatusPrintBean(Integer idStatus) {
        this.idStatus = idStatus;
    }

    public CatStatusPrintBean(Integer idStatus, String nameStatus, Integer active) {
        this.idStatus = idStatus;
        this.nameStatus = nameStatus;
        this.active = active;
    }

    public Integer getIdStatus() {
        return idStatus;
    }

    public void setIdStatus(Integer idStatus) {
        this.idStatus = idStatus;
    }

    public String getNameStatus() {
        return nameStatus;
    }

    public void setNameStatus(String nameStatus) {
        this.nameStatus = nameStatus;
    }

    public String getDescStatus() {
        return descStatus;
    }

    public void setDescStatus(String descStatus) {
        this.descStatus = descStatus;
    }

    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idStatus != null ? idStatus.hashCode() : 0);
        return hash;
    }
}

这是我在 dao 中的方法:

public List<CatStatusPrintBean> getCatStatusPrint2(){
    session2 = sqlSessionFactory2.openSession();
    try {
        List<CatStatusPrintBean> lstStatus = session2.selectList(TagsPrintConstants.MAPPER_CONSULT_STATUS);            
         return lstStatus;
    } catch (Exception e) {
        LOG.error(TagsPrintConstants.ERROR_OBTENER_CAT_IMPRESION + e.getMessage());
        return null;
    } finally {
        session2.close();
    }
}  

为什么我得到和错误???????提前致谢!!

4

1 回答 1

2

看来我的配置指向不同的数据库。一旦我将它指向正确的数据库,它就可以工作。

于 2013-10-02T22:10:20.140 回答