Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Date <-> Timestamp converter ignored after upgrading from 3.4.2 to 3.5 #3823

Closed
axelfontaine opened this issue Nov 29, 2014 · 7 comments

Comments

@axelfontaine
Copy link

In my pom.xml jooq generator config I have this:

<database>
    <name>org.jooq.util.postgres.PostgresDatabase</name>
    <includes>.*</includes>
    <inputSchema>abc</inputSchema>
    <customTypes>
           <customType>
                  <name>BinaryEncrypted</name>
                  <type>byte[]</type>
                  <converter>abc.jooq.BinaryEncryptedConverter</converter>
           </customType>
           <customType>
                   <name>IntEncrypted</name>
                   <type>java.lang.Integer</type>
                   <converter>abc.jooq.IntEncryptedConverter</converter>
            </customType>
            <customType>
                    <name>Utf8Encrypted</name>
                    <type>java.lang.String</type>
                    <converter>abc.jooq.Utf8EncryptedConverter</converter>
             </customType>
             <customType>
                     <name>TimestampDate</name>
                     <type>java.util.Date</type>
                     <converter>abc.jooq.TimestampConverter</converter>
             </customType>
             ...

All worked fine in 3.4.2.

With the 3.5.0 upgrade (version bump in the pom, no other changes), the TimestampConverter started being ignored.

Here is the source:

public class TimestampConverter implements Converter<Timestamp, Date> {
    @Override
    public Date from(Timestamp databaseObject) {
        if (databaseObject == null) {
            return null;
        }
        return new Date(databaseObject.getTime());
    }

    @Override
    public Timestamp to(Date userObject) {
        if (userObject == null) {
            return null;
        }
        return new Timestamp(userObject.getTime());
    }

    @Override
    public Class<Timestamp> fromType() {
        return Timestamp.class;
    }

    @Override
    public Class<Date> toType() {
        return Date.class;
    }
}

This generator runs without errors, however now the compiler stumbles with:

[ERROR] /abc/Def.java:[31,35] incompatible types: java.util.Date cannot be converted to java.sql.Timestamp
[ERROR] /abc/Def.java:[61,46] no suitable method found for between(java.util.Date,java.util.Date)
[ERROR] method org.jooq.Field.between(java.sql.Timestamp,java.sql.Timestamp) is not applicable
[ERROR] (argument mismatch; java.util.Date cannot be converted to java.sql.Timestamp)
[ERROR] method org.jooq.Field.between(org.jooq.Field<java.sql.Timestamp>,org.jooq.Field<java.sql.Timestamp>) is not applicable
[ERROR] (argument mismatch; java.util.Date cannot be converted to org.jooq.Field<java.sql.Timestamp>)
[ERROR] /abc/Def.java:[29,75] no suitable method found for gt(java.util.Date)
[ERROR] method org.jooq.Field.gt(java.sql.Timestamp) is not applicable
[ERROR] (argument mismatch; java.util.Date cannot be converted to java.sql.Timestamp)
[ERROR] method org.jooq.Field.gt(org.jooq.Field<java.sql.Timestamp>) is not applicable
[ERROR] (argument mismatch; java.util.Date cannot be converted to org.jooq.Field<java.sql.Timestamp>)
[ERROR] method org.jooq.Field.gt(org.jooq.Select<? extends org.jooq.Record1<java.sql.Timestamp>>) is not applicable
[ERROR] (argument mismatch; java.util.Date cannot be converted to org.jooq.Select<? extends org.jooq.Record1<java.sql.Timestamp>>)
[ERROR] method org.jooq.Field.gt(org.jooq.QuantifiedSelect<? extends org.jooq.Record1<java.sql.Timestamp>>) is not applicable
[ERROR] (argument mismatch; java.util.Date cannot be converted to org.jooq.QuantifiedSelect<? extends org.jooq.Record1<java.sql.Timestamp>>)

Changing the version in the pom back to 3.4.2 fixes all errors.

@lukaseder
Copy link
Member

Can you please show your <forcedTypes/> configuration? That's where a couple of changes were implemented...

@axelfontaine
Copy link
Author

Sure.

                            <forcedTypes>
                                <forcedType>
                                    <name>BinaryEncrypted</name>
                                    <expression>.*_x</expression>
                                    <types>bytea</types>
                                </forcedType>
                                <forcedType>
                                    <name>IntEncrypted</name>
                                    <expression>.*_xi</expression>
                                    <types>bytea</types>
                                </forcedType>
                                <forcedType>
                                    <name>Utf8Encrypted</name>
                                    <expression>.*_x8</expression>
                                    <types>bytea</types>
                                </forcedType>
                                <forcedType>
                                    <name>TimestampDate</name>
                                    <expression>.*_utc</expression>
                                    <types>timestamp without time zone</types>
                                </forcedType>
...

@lukaseder
Copy link
Member

Hmm, so am I right that this is mostly about the TimestampDate type / converter, and the timestamp without time zone data type? That type is not in SQLDataType, which is probably why it doesn't really work. I'm not sure why it worked before, though - I'll investigate. Does this temporarily fix the issue?

                                <forcedType>
                                    <name>TimestampDate</name>
                                    <expression>.*_utc</expression>
                                    <types>timestamp.*</types>
                                </forcedType>

@axelfontaine
Copy link
Author

Bingo! Yes, that did it!

@sebhoss
Copy link

sebhoss commented Dec 9, 2014

I'm experiencing the same problem:

custom types:

<customTypes>
  <customType>
    <name>Instant</name>
    <type>org.joda.time.Instant</type>
    <converter>my.converter.TimestampToInstantConverter</converter>
  </customType>
</customTypes>

forced types:

<forcedTypes>
  <forcedType>
    <name>Instant</name>
    <types>timestamp without time zone</types>
  </forcedType>
</forcedTypes>

This works fine up until 3.4.4 but breaks in 3.5.0. Changing the types element value to timestamp.* fixes this.

@lukaseder
Copy link
Member

@sebhoss: thanks for the additional info

@lukaseder
Copy link
Member

This works again in jOOQ 3.10, probably because of the fix in #5872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants