1

My current jooq-codegen-maven configuration maps all tinyint(1) fields to java's boolean values:

<forcedTypes>
    <forcedType>
        <name>BOOLEAN</name>
        <types>(?i:TINYINT)</types>
    </forcedType>
</forcedTypes>

Issue is that in some cases DB contains columns marked as tinyint(3) which should not be treated as boolean but some real int. Unfortunately I could not find any examples, docs have something but it didn't really worked for me:

<forcedType>
   <name>BOOLEAN</name>
   <types>TINYINT\(1\)</types>
</forcedType>
nKognito
  • 6,297
  • 17
  • 77
  • 138
  • Note that even if this worked, your regular expression is escaped incorrectly. You meant to write `TINYINT\(1\)` – Lukas Eder Aug 06 '18 at 07:17

1 Answers1

3

Starting from jOOQ 3.12

We've implemented support for reading the numeric display width from MySQL in the code generator. You can match it using:

<forcedType>
  <name>BOOLEAN</name>
  <includeTypes>
    (?i:(TINY|SMALL|MEDIUM|BIG)?INT(UNSIGNED)?\(1\))
  </includeTypes>
</forcedType>

This is documented in this blog post: https://blog.jooq.org/2019/09/27/how-to-map-mysqls-tinyint1-to-boolean-in-jooq/

This was implemented with: https://github.com/jOOQ/jOOQ/issues/7719

Until jOOQ 3.11

Prior to jOOQ 3.12, the jOOQ code generator did not consider the display width of types like TINYINT for the <types/> regular expression, simply because it reads only INFORMATION_SCHEMA.DATA_TYPE (which doesn't contain this information), instead of INFORMATION_SCHEMA.COLUMN_TYPE (which does).

If upgrading to 3.12 is not an option, you may either:

  • Enumerate all your boolean types in that <forcedType/> specification
  • Write a programmatic code generator configuration where you query INFORMATION_SCHEMA.COLUMN_TYPE to generate the set of columns that need to be forced to type BOOLEAN
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509