【问题标题】:How to solve indexOutOfBounds error in MyBatis selectForUpdate?如何解决 MyBatis selectForUpdate 中的 indexOutOfBounds 错误?
【发布时间】:2020-10-30 11:49:06
【问题描述】:

我使用 postgreSQL。这是我在 myBatisMapper 中的请求:

<select id="findByStatusAndIdentityAndPrvCode" parameterType="java.lang.String" resultMap="Request">
        select
        from req_tab
        where status in ('I', 'D', 'Q')
          and identity = #{identity}
          and prv_code = #{prvCode}
        limit 1 for update
    </select>

这是我的错误:

org.apache.ibatis.exceptions.PersistenceException: 
Error querying database.  Cause: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
The error may exist in ru/infogate/dao/mapper/ReqMapper.xml
The error may involve ru.infogate.dao.mapper.ReqMapper.findByStatusAndIdentityAndPrvCode
The error occurred while handling results
SQL: select         from req_tab         where status in ('I', 'D', 'Q')           and identity = ?           and prv_code = ?         limit 1 for update
Cause: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

是什么原因以及如何解决?

【问题讨论】:

    标签: java mybatis spring-mybatis mybatis-mapper mybatis-sql


    【解决方案1】:

    您可以通过添加不带参数的构造函数和带参数的构造函数来修复

        //Add Constructor with no arguments to fix this error
        public UserAdmin() {
        }
        //Along side the constructor with arguments
        public UserAdmin(String username, String password, String email, Date date_created, Date date_expired) {
            this.username = username;
            this.password = password;
            this.email = email;
            this.date_created = date_created;
            this.date_expired = date_expired;
        }
    
    

    【讨论】:

      【解决方案2】:

      我在使用 mysql 时遇到同样的错误。但我通过同时添加 NoArgsConstructor 和 AllArgsConstructor 解决了这个问题。我使用 lombok 的 @Builder 但错过了构造函数注释。 错误日志显示的消息太少,无法找到。

      【讨论】:

        【解决方案3】:

        我解决了这个问题。只需要将 allArgs 构造函数添加到我的实体中

        【讨论】:

          猜你喜欢
          • 2016-06-02
          • 1970-01-01
          • 1970-01-01
          • 2017-12-24
          • 1970-01-01
          • 2012-09-14
          • 2017-10-06
          • 2020-11-01
          • 2016-12-26
          相关资源
          最近更新 更多