SQL 到 JOOQ 翻译:类型错误

SQL to JOOQ translation: type error

我正在尝试将以下 SQL 语句翻译成 JOOQ:

UPDATE training_content
SET indx = (
    SELECT SUM(indx)
    FROM training_content
    WHERE indx = ? OR indx = ?
) - indx
WHERE indx = ? OR indx = ?;

sqlite 数据库如下所示:

CREATE TABLE training_content (
  training_id INTEGER NOT NULL,
  set_id INTEGER NOT NULL,
  indx INTEGER NOT NULL,
  FOREIGN KEY(training_id) REFERENCES training(training_id) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY(set_id) REFERENCES sets(set_id) ON DELETE CASCADE ON UPDATE CASCADE
);

sql语句交换两个索引,用于在列表中排列集合对象,这样调用:

public void updateIndex(Training t, int index, boolean up) throws SQLException {
    updateIndexStmt.setInt(1, index);
    updateIndexStmt.setInt(2, index + (up ? -1 : 1));
    updateIndexStmt.setInt(3, index);
    updateIndexStmt.setInt(4, index + (up ? -1 : 1));
    updateIndexStmt.executeUpdate();
}

因为我要从普通的 JDBC 转向 JOOQ,所以我试图将其翻译成这样:

public void updateIndex(Training t, int index, boolean up) throws SQLException {
    create.update(TRAINING_CONTENT)
            .set(TRAINING_CONTENT.INDX,
                    DSL.select(DSL.sum(TRAINING_CONTENT.INDX).minus(TRAINING_CONTENT.INDX))
                            .from(TRAINING_CONTENT)
                            .where(TRAINING_CONTENT.INDX.equal(index)
                                    .or(TRAINING_CONTENT.INDX.equal(index + (up ? -1 : +1))))
            );
}

但我收到了我在 Java 中收到的最奇怪和最长的错误消息:

Error:(50, 17) java: no suitable method found for set(org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer>,org.jooq.SelectConditionStep<org.jooq.Record1<java.math.BigDecimal>>)
method org.jooq.UpdateSetStep.<T>set(org.jooq.Field<T>,T) is not applicable
  (inference variable T has incompatible bounds
    equality constraints: java.lang.Integer
    lower bounds: org.jooq.SelectConditionStep<org.jooq.Record1<java.math.BigDecimal>>)
method org.jooq.UpdateSetStep.<T>set(org.jooq.Field<T>,org.jooq.Field<T>) is not applicable
  (cannot infer type-variable(s) T
    (argument mismatch; org.jooq.SelectConditionStep<org.jooq.Record1<java.math.BigDecimal>> cannot be converted to org.jooq.Field<T>))
method org.jooq.UpdateSetStep.<T>set(org.jooq.Field<T>,org.jooq.Select<? extends org.jooq.Record1<T>>) is not applicable
  (inferred type does not conform to equality constraint(s)
    inferred: java.math.BigDecimal
    equality constraints(s): java.math.BigDecimal,java.lang.Integer)
method org.jooq.UpdateSetFirstStep.<T1>set(org.jooq.Row1<T1>,org.jooq.Row1<T1>) is not applicable
  (cannot infer type-variable(s) T1
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row1<T1>))
method org.jooq.UpdateSetFirstStep.<T1,T2>set(org.jooq.Row2<T1,T2>,org.jooq.Row2<T1,T2>) is not applicable
  (cannot infer type-variable(s) T1,T2
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row2<T1,T2>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3>set(org.jooq.Row3<T1,T2,T3>,org.jooq.Row3<T1,T2,T3>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row3<T1,T2,T3>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4>set(org.jooq.Row4<T1,T2,T3,T4>,org.jooq.Row4<T1,T2,T3,T4>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row4<T1,T2,T3,T4>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5>set(org.jooq.Row5<T1,T2,T3,T4,T5>,org.jooq.Row5<T1,T2,T3,T4,T5>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row5<T1,T2,T3,T4,T5>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6>set(org.jooq.Row6<T1,T2,T3,T4,T5,T6>,org.jooq.Row6<T1,T2,T3,T4,T5,T6>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row6<T1,T2,T3,T4,T5,T6>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7>set(org.jooq.Row7<T1,T2,T3,T4,T5,T6,T7>,org.jooq.Row7<T1,T2,T3,T4,T5,T6,T7>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row7<T1,T2,T3,T4,T5,T6,T7>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8>set(org.jooq.Row8<T1,T2,T3,T4,T5,T6,T7,T8>,org.jooq.Row8<T1,T2,T3,T4,T5,T6,T7,T8>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row8<T1,T2,T3,T4,T5,T6,T7,T8>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9>set(org.jooq.Row9<T1,T2,T3,T4,T5,T6,T7,T8,T9>,org.jooq.Row9<T1,T2,T3,T4,T5,T6,T7,T8,T9>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row9<T1,T2,T3,T4,T5,T6,T7,T8,T9>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>set(org.jooq.Row10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>,org.jooq.Row10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>set(org.jooq.Row11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>,org.jooq.Row11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>set(org.jooq.Row12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>,org.jooq.Row12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>set(org.jooq.Row13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>,org.jooq.Row13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>set(org.jooq.Row14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>,org.jooq.Row14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>set(org.jooq.Row15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>,org.jooq.Row15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>set(org.jooq.Row16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>,org.jooq.Row16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>set(org.jooq.Row17<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>,org.jooq.Row17<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row17<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>set(org.jooq.Row18<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>,org.jooq.Row18<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row18<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>set(org.jooq.Row19<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>,org.jooq.Row19<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row19<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>set(org.jooq.Row20<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>,org.jooq.Row20<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row20<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>set(org.jooq.Row21<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>,org.jooq.Row21<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row21<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>set(org.jooq.Row22<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>,org.jooq.Row22<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row22<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>))
method org.jooq.UpdateSetFirstStep.<T1>set(org.jooq.Row1<T1>,org.jooq.Select<? extends org.jooq.Record1<T1>>) is not applicable
  (cannot infer type-variable(s) T1
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row1<T1>))
method org.jooq.UpdateSetFirstStep.<T1,T2>set(org.jooq.Row2<T1,T2>,org.jooq.Select<? extends org.jooq.Record2<T1,T2>>) is not applicable
  (cannot infer type-variable(s) T1,T2
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row2<T1,T2>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3>set(org.jooq.Row3<T1,T2,T3>,org.jooq.Select<? extends org.jooq.Record3<T1,T2,T3>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row3<T1,T2,T3>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4>set(org.jooq.Row4<T1,T2,T3,T4>,org.jooq.Select<? extends org.jooq.Record4<T1,T2,T3,T4>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row4<T1,T2,T3,T4>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5>set(org.jooq.Row5<T1,T2,T3,T4,T5>,org.jooq.Select<? extends org.jooq.Record5<T1,T2,T3,T4,T5>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row5<T1,T2,T3,T4,T5>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6>set(org.jooq.Row6<T1,T2,T3,T4,T5,T6>,org.jooq.Select<? extends org.jooq.Record6<T1,T2,T3,T4,T5,T6>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row6<T1,T2,T3,T4,T5,T6>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7>set(org.jooq.Row7<T1,T2,T3,T4,T5,T6,T7>,org.jooq.Select<? extends org.jooq.Record7<T1,T2,T3,T4,T5,T6,T7>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row7<T1,T2,T3,T4,T5,T6,T7>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8>set(org.jooq.Row8<T1,T2,T3,T4,T5,T6,T7,T8>,org.jooq.Select<? extends org.jooq.Record8<T1,T2,T3,T4,T5,T6,T7,T8>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row8<T1,T2,T3,T4,T5,T6,T7,T8>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9>set(org.jooq.Row9<T1,T2,T3,T4,T5,T6,T7,T8,T9>,org.jooq.Select<? extends org.jooq.Record9<T1,T2,T3,T4,T5,T6,T7,T8,T9>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row9<T1,T2,T3,T4,T5,T6,T7,T8,T9>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>set(org.jooq.Row10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>,org.jooq.Select<? extends org.jooq.Record10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>set(org.jooq.Row11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>,org.jooq.Select<? extends org.jooq.Record11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>set(org.jooq.Row12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>,org.jooq.Select<? extends org.jooq.Record12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>set(org.jooq.Row13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>,org.jooq.Select<? extends org.jooq.Record13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>set(org.jooq.Row14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>,org.jooq.Select<? extends org.jooq.Record14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>set(org.jooq.Row15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>,org.jooq.Select<? extends org.jooq.Record15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>set(org.jooq.Row16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>,org.jooq.Select<? extends org.jooq.Record16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>set(org.jooq.Row17<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>,org.jooq.Select<? extends org.jooq.Record17<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row17<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>set(org.jooq.Row18<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>,org.jooq.Select<? extends org.jooq.Record18<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row18<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>set(org.jooq.Row19<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>,org.jooq.Select<? extends org.jooq.Record19<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row19<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>set(org.jooq.Row20<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>,org.jooq.Select<? extends org.jooq.Record20<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row20<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>set(org.jooq.Row21<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>,org.jooq.Select<? extends org.jooq.Record21<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row21<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>))
method org.jooq.UpdateSetFirstStep.<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>set(org.jooq.Row22<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>,org.jooq.Select<? extends org.jooq.Record22<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>>) is not applicable
  (cannot infer type-variable(s) T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22
    (argument mismatch; org.jooq.TableField<ch.tiim.sco.database.jooq.tables.records.TrainingContentRecord,java.lang.Integer> cannot be converted to org.jooq.Row22<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>))

编辑

这个 JOOQ 代码几乎可以工作:

update(TRAINING_CONTENT)
            .set(TRAINING_CONTENT.INDX,
                    select(sum(t.INDX).minus(TRAINING_CONTENT.INDX).coerce(Integer.class))
                            .from(t)
                            .where(t.INDX.equal(index)
                                    .or(t.INDX.equal(index + (up ? -1 : +1))))
            ).where(TRAINING_CONTENT.INDX.equal(index)
                    .or(TRAINING_CONTENT.INDX.equal(index + (up ? -1 : +1))))

但它生成以下 SQL:

update training_content 
set indx = (
  select (sum(t.indx) - training_content.indx)
  from training_content t 
  where (t.indx = 2 or t.indx = 1)
) 
where (training_content.indx = 2 or training_content.indx = 1);

但是 select (sum(t.indx) - training_content.indx) 部分无法像我原来的 SQL 代码那样工作:它为两列选择相同的值而不是切换它们。

错误消息确实有点误导,因为编译器似乎列出了所有可能适用的重载 set() 方法。出现编译错误的原因是 set() 调用的左侧是 Field<Integer>:

TRAINING_CONTENT.INDX

而右边是一个Select<Record1<BigDecimal>>(注意DSL.sum() returns一个Field<BigDecimal>):

DSL.select(DSL.sum(TRAINING_CONTENT.INDX).minus(TRAINING_CONTENT.INDX))

但是set()调用签名是这样的:

<T> UpdateSetMoreStep<R> set(Field<T> field,
                             Select<? extends Record1<T>> value)

最简单的解决方案是将您的右侧也强制为 Integer:

DSL.select(DSL.sum(TRAINING_CONTENT.INDX)
              .minus(TRAINING_CONTENT.INDX)
              .coerce(Integer.class))

关于查询本身的注释

您对 minus() 的调用不会那样工作。如果要引用 UPDATE 语句中的 TRAINING_CONTENT.INDX 列,则需要在嵌套 select 中为 TRAINING_CONTENT table 添加别名。像这样:

TrainingContent t = TRAINING_CONTENT.as("t");

create.update(TRAINING_CONTENT)
      .set(TRAINING_CONTENT.INDX,
           select(sum(t.INDX).minus(TRAINING_CONTENT.INDX))
           .from(t)
           .where(t.INDX.equal(index)
           .or(t.INDX.equal(index + (up ? -1 : +1))))
      );