Search code examples
jooq

JOOQ IllegalArgumentException: Field () is not contained in Row


I am really confused by this and am not able to reason with the error at all.

Integer id = 5;
        if (id != null)
        {
            final var configurationResult = context.select(Configuration.CONFIGURATION)
                    .from(Configuration.CONFIGURATION)
                    .where(Configuration.CONFIGURATION.DEVICE_ID.eq(id))
                    .fetch();

            configurationResult.forEach(configuration -> {
                final var minTemp = configuration.getValue(Configuration.CONFIGURATION.MINIMUM_TEMPERATURE_THRESHOLD);
               System.out.println("MinimumTemp is: " + minTemp);
            });
        }

the exception is the most confusing:

Exception in thread "" java.lang.IllegalArgumentException: Field ("public"."configuration"."minimum_temperature_threshold") is not contained in Row (row (
  "public"."configuration"."configuration_id",
  "public"."configuration"."minimum_temperature_threshold",
  "public"."configuration"."maximum_temperature_threshold",
  "public"."configuration"."ideal_temperature",
  "public"."configuration"."minimum_ph_threshold",
  "public"."configuration"."maximum_ph_threshold",
  "public"."configuration"."ideal_ph",
  "public"."configuration"."light_on_time",
  "public"."configuration"."light_off_time",
  "public"."configuration"."update_time",
  "public"."configuration"."device_id"
))

If I print the contents of the result I get the following

|configuration                                     |
|(6, 22, 28, 24, 7, 9, 8, 2023-05-15T18:00, 2023...|

So the data is there.

Can someone help me understand what is happening and help direct me in the right direction?

Damien


Solution

  • When you pass the table reference to your select() clause, then you're projecting a nested record. See the manual sections about:

    This works just like in native PostgreSQL and offers powerful ways of nesting multiple TableRecord types.

    If you require only a single column (CONFIGURATION.MINIMUM_TEMPERATURE_THRESHOLD), then it should be sufficient to project only that.

    I agree that the error message is confusing here. Row (row ( is a (very) subtle hint at the problem, which isn't at all obvious. I've created an issue to address the error message: #15085