The jOOQ User Manual. Multiple Pages : Code generation : Advanced generator configuration : Generate : Java Time Types | previous : next |
With jOOQ 3.9, support for JSR-310 java.time
types has been added to the jOOQ API and to the code generator. Users of Java 8 can now specify that the jOOQ code generator should prefer JSR 310 types over their equivalent JDBC types. This includes:
- java.time.LocalDate instead of java.sql.Date
- java.time.LocalTime instead of java.sql.Time
- java.time.LocalDateTime instead of java.sql.Timestamp
Semantically, the above types are exactly equivalent, although the new types do away with the many flaws of the JDBC types. If there is no JDBC type for an equivalent JSR 310 type, then the JSR 310 type is generated by default. This includes
-
java.time.OffsetTime (for SQL
TIME WITH TIME ZONE
) -
java.time.OffsetDateTime (for SQL
TIMESTAMP WITH TIME ZONE
)
To get more fine-grained control of the above, you may wish to consider applying data type rewriting.
In order to activate the generation of these types, use:
XML configuration (standalone and Maven)
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.10.0.xsd"> <generator> <generate> <javaTimeTypes>true</javaTimeTypes> </generate> </generator> </configuration>
Programmatic configuration
configuration .withGenerator(new Generator( .withGenerate(new Generate() .withJavaTimeTypes(true))));
Gradle configuration
myConfigurationName(sourceSets.main) { generator { generate { javaTimeTypes = true } } }