Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java iBatis无提示映射列失败_Java_Sql_Ibatis - Fatal编程技术网

Java iBatis无提示映射列失败

Java iBatis无提示映射列失败,java,sql,ibatis,Java,Sql,Ibatis,当我使用iBatis映射POJO时,如下所示: Person { String firstName String lastName; } 要查询: select firstName, last_name from Person 我发现Person.firstName填充正确,而Person.lastName为空-这是静默进行的。我可以通过翻译last_name->lastName引入ResultMap来修复空问题,但我希望iBatis在尝试映射时抛出错误,而不是尽其所能默默地

当我使用iBatis映射POJO时,如下所示:

Person {
    String firstName
    String lastName;
}
要查询:

select firstName, last_name from Person
我发现Person.firstName填充正确,而Person.lastName为空-这是静默进行的。我可以通过翻译last_name->lastName引入ResultMap来修复空问题,但我希望iBatis在尝试映射时抛出错误,而不是尽其所能默默地

有人知道我怎么做吗

谢谢

您可以尝试:

我看到了几个问题

我瞎了! 类Person{String firstName String lastName;} 为iBatis提供0个可见元素,因为iBatis既不扩展Person,也不共享Person的包。考虑以下事项:

public class Person
{
    private String firstName;
    private String lastName;

    public String getFirstName()
    {
        return firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setFirstName(final String newValue)
    {
        firstName = newValue;
    }

    public void setLastName(final String newValue)
    {
        lastName = newValue;
    }
}
<resultMap id="theIdOfThisMap"
           class="Person">
    <result property="firstName" column="firstName"/>
    <result property="lastName" column="last_name"/>
</resultMap>

<select id="searchForEntities"
        resultMap="theIdOfThisMap">
    select
        firstName,
        last_name
    from
        PERSON
</select>
分而治之 姓氏与姓氏完全不同。 考虑使用如下的结果图:

public class Person
{
    private String firstName;
    private String lastName;

    public String getFirstName()
    {
        return firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setFirstName(final String newValue)
    {
        firstName = newValue;
    }

    public void setLastName(final String newValue)
    {
        lastName = newValue;
    }
}
<resultMap id="theIdOfThisMap"
           class="Person">
    <result property="firstName" column="firstName"/>
    <result property="lastName" column="last_name"/>
</resultMap>

<select id="searchForEntities"
        resultMap="theIdOfThisMap">
    select
        firstName,
        last_name
    from
        PERSON
</select>

iBatis不会自动将SQL约定名称映射到Java约定名称吗?我的意思是,iBatis是否应该自动尝试将列last_name映射到Java字段lastName?只是好奇。嗨,DwB-我已经让ResultMap工作了,Person类是用来说明参数名的,不是可见性的,所以我对混淆表示歉意。我担心的是,当iBatis无法将数据库列映射到等效的类属性时(例如,在没有ResultMap的情况下),iBatis似乎不会发出警告-您知道我如何强制它发出警告/错误,因为这将有助于在开发过程中快速发现错误?iBatis声称它将映射与类中的属性匹配的任何列。last_name和lastName不匹配,因此它们不在语句的范围内。语句将映射匹配的任何列。我不知道如何让ibatis从查询中识别不匹配的列。