Hi Urs, Thanks for following up. That approach isn't strictly the same as jOOQ will now bind java.sql.Date values to the JDBC driver, which means that hours will always be truncated. The goal is for a java.sql.Timestamp (or oracle.sql.DATE) value to be bound to your JDBC statements. A better option would be to use a data type binding, where you're in control of how jOOQ binds your Timestamp value to JDBC: https://www.jooq.org/doc/latest/manual/code-generation/custom-data-type-bindings
I hope this helps, Lukas On Mon, Sep 24, 2018 at 5:02 PM Urs Hofmänner <[email protected]> wrote: > Hi Lukas > > I've possibly found a workaround. > > Instead of the option dateAsTimestamp I declare a converter in the code > generation's config: > > <configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.10.0.xsd"> > <!-- Configure the database connection here --> > <jdbc> > > ... > </jdbc> > > <generator> > > <database> > > ... > > <!-- > https://www.jooq.org/doc/3.11/manual/code-generation/codegen-advanced/codegen-config-database/codegen-database-date-as-timestamp/ > <dateAsTimestamp>true</dateAsTimestamp> > --> > > <!-- Associate data type rewrites with database columns --> > <forcedTypes> > <forcedType> > > <userType>java.sql.Timestamp</userType> > > > <converter>....persistence.database.jooq.converter.OracleDateConverter</converter> > > > <!-- Add a Java regular expression matching > fully-qualified columns. Use the pipe to separate several expressions. > If provided, both "expressions" and "types" must > match. --> > > <expression>....</expression> > > <types>DATE</types> > > </forcedType> > > </forcedTypes> > </database> > > ... > > > and provide a converter like > > public class OracleDateConverter extends AbstractConverter<java.sql.Date, > java.sql.Timestamp> { > > > public OracleDateConverter() { > this(java.sql.Date.class, java.sql.Timestamp.class); > > } > > public OracleDateConverter(Class<Date> fromType, Class<Timestamp> toType) > { > super(fromType, toType); > } > > @Override > public Timestamp from(Date databaseObject) { > if(databaseObject == null) { > return null; > } > return new Timestamp(databaseObject.getTime()); > } > > @Override > public Date to(Timestamp userObject) { > if(userObject == null) { > return null; > } > return new Date(userObject.getTime()); > } > } > > > Regards, > Urs > > -- > You received this message because you are subscribed to the Google Groups > "jOOQ User Group" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
