1

Synopsis: I'm trying to create an SQL update using jOOQ

DSL.using(connection)
.update(DSL.table("dogs"))
.set(DSL.field("age"), DSL.field("age").add(1))
.set(DSL.field("rabies"), "true")
.where(DSL.field("id").eq("Kujo"))
.execute();

Issue:

The method set(Field<Object>, Object) is ambiguous for the type UpdateSetFirstStep<Record>

Question: How do I create this update using jOOQ?

jarlh
  • 42,561
  • 8
  • 45
  • 63
stackoverflow
  • 18,348
  • 50
  • 129
  • 196
  • A [mcve] is a great start when asking SQL questions. Don't forget to show us your current SQL attempt. – jarlh Dec 03 '21 at 14:31
  • 2
    @jarlh: What's not minimal or reproducible about this example? – Lukas Eder Dec 03 '21 at 14:37
  • No sample data, no expected result. No SQL. – jarlh Dec 03 '21 at 14:38
  • 1
    @jarlh: Everything needed to answer the question is there. There is no need for sample data, or expected results, or SQL when the problem is related to jOOQ and why the Java compiler cannot compile a jOOQ query. – Lukas Eder Dec 03 '21 at 14:41
  • I removed the tag, since this doesn't seem to need any SQL assistance. – jarlh Dec 03 '21 at 15:08

1 Answers1

1

You ran into this problem: Reference is ambiguous with generics

Fixing your query

It's always a good idea to attach data types with your jOOQ expressions. In your particular case, you can work around the problem by specifying things like:

DSL.field("age", SQLDataType.INTEGER)

Or, shorter, with the usual static imports:

field("age", INTEGER)

Using the code generator

However, jOOQ is best used with its code generator, see also this article here. Not only will you avoid problems like these, but you also get compile time type safety (of data types and meta data), advanced features like implicit joins and much more.

Your query would then look like this:

DSL.using(connection)
   .update(DOGS)
   .set(DOGS.AGE, DOGS.AGE.add(1))
   .set(DOGS.RABIES, true)
   .where(DOGS.ID.eq("Kujo"))
   .execute();
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • Awesome! Thanks so much for your help Lukas. This was very informative – stackoverflow Dec 03 '21 at 14:48
  • 1
    @stackoverflow: For more infos about why you should use the code generator, see also [this article that I've written now](https://blog.jooq.org/why-you-should-use-jooq-with-code-generation/), as these problems are very frequent among users of jOOQ without code generation – Lukas Eder Dec 06 '21 at 11:58
  • Thanks Lukas, this has been most helpful! – stackoverflow Dec 06 '21 at 16:48