Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Force all DATE columns to LocalDateTime in jOOQ generator?

Tags:

java

sql

jooq

I want to force all Oracle DATE columns to LocalDateTime.

What I tried:

<forcedType>
    <name>LOCALDATETIME</name>
    <userType>java.time.LocalDateTime</userType>
    <types>DATE\(*\)</types>
</forcedType>

But jOOQ still generates LocalDate.

How must the forcedType look like?

like image 366
Simon Martinelli Avatar asked Sep 02 '25 07:09

Simon Martinelli


1 Answers

Your <types> expression reads "DATE followed by any number of ( followed by exactly one ). You probably wanted this:

<types>DATE(\(.*\))?</types>

As a side note: You don't really need to specify the <userType> to profit from the "data type rewriting" feature. Specifying a name that matches a type from SQLDataType is enough.

Bug

Notice there was a bug in jOOQ 3.11 by which <name>LOCALDATETIME</name> did not work: https://github.com/jOOQ/jOOQ/issues/8493

This is fixed in jOOQ 3.12. For the time being, use <name>TIMESTAMP</name> instead, along with <javaTimeTypes>

like image 68
Lukas Eder Avatar answered Sep 04 '25 21:09

Lukas Eder