javajooqjooq-codegen-mavenjooq-codegenspring-boot-jooq

How to remove table name prefixes in class names with jOOQ?


I'm using jooq-codegen to generate Java classes from my database schemas, but I'm encountering an issue with table name prefixes. For instance, a table named t_user ends up generating a class named TUser when I would prefer it to be User (without the 'T' prefix).

How can I configure jooq-codegen to strip specific prefixes from table names during class generation? Any advice on possible configurations or workarounds in the XML configuration file would be greatly appreciated.

Thank you!

I checked the jOOQ documentation and found examples of adding prefixes, but there doesn't seem to be a direct way to remove prefixes.

<configuration>
  <generator>
    <strategy>
      <matchers>
        <tables>
          <table>
            <tableIdentifier>
              <transform>UPPER</transform>
              <expression>T_$0</expression>
            </tableIdentifier>
            <tableClass>
              <transform>PASCAL</transform>
              <expression>T_$0</expression>
            </tableClass>
          </table>
        </tables>
      </matchers>
    </strategy>
  </generator>
</configuration>

Solution

  • Do this:

    <configuration>
      <generator>
        <strategy>
          <matchers>
            <tables>
              <table>
    
                <!-- Match only relevant tables, capture the name suffix -->
                <expression>T_(.*)</expression>
    
                <!-- Reference the captured group $1 -->
                <tableIdentifier>
                  <transform>UPPER</transform>
                  <expression>$1</expression>
                </tableIdentifier>
                <tableClass>
                  <transform>PASCAL</transform>
                  <expression>$1</expression>
                </tableClass>
              </table>
            </tables>
          </matchers>
        </strategy>
      </generator>
    </configuration>
    

    It's probably worth adding an example in the documentation page about matcher rules as well. I've created a feature request for this: