Как решить ошибку indexOutOfBounds в MyBatis selectForUpdate?

Я использую 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

Что такое причина и как ее решить?

3 ответа

Я встречаю ту же ошибку при использовании mysql. Но я решил это, добавив как NoArgsConstructor, так и AllArgsConstructor. Я использую @Builder of lombok, но пропустил аннотацию конструктора. В журнале ошибок слишком мало сообщений, чтобы их найти.

Вы можете исправить, добавив конструктор без аргументов, наряду с конструктором с аргументами

          //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;
    }

Я решил проблему. Просто нужно добавить конструктор allArgs в мою сущность

Другие вопросы по тегам