Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create 'update' using multiple 'set' methods

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>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Question: How do I create this update using jOOQ?

>Solution :

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. 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();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading