arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
438 stars 76 forks source link

Problem mapping TIMESTAMP WITH TIMEZONE to OffsetDateTime using SelectQueryMapper #729

Open gilinykh opened 4 years ago

gilinykh commented 4 years ago

Having this table in database:

create table test(
    created_at timestamp with time zone default now()
);

And this JOOQ's generated field for table's column:

public final TableField<TestRecord, OffsetDateTime> CREATED_AT = createField(DSL.name("CREATED_AT"), org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE.precision(6).defaultValue(org.jooq.impl.DSL.field("NOW()", org.jooq.impl.SQLDataType.TIMESTAMPWITHTIMEZONE)), this, "");

When querying that table using SelectQueryMapper:

@Getter
@AllArgsConstructor
public class TestData {
    private final OffsetDateTime createdAt;
}

List<TestData> list = SelectQueryMapperFactory.newInstance().newMapper(TestData.class).asList(dsl.select().from(TEST));

Mapping error occurs:

org.jooq.exception.MappingException: Could not find eligible property for 'CREATED_AT' on  class TestData not found  See https://github.com/arnaudroger/SimpleFlatMapper/wiki/Errors_PROPERTY_NOT_FOUND

    at org.simpleflatmapper.jooq.SelectQueryMapper.getMapper(SelectQueryMapper.java:186)
    at org.simpleflatmapper.jooq.SelectQueryMapper.asList(SelectQueryMapper.java:46)
        ...

sfm-jooq v. 8.2.3 is used

arnaudroger commented 4 years ago

Will have a look thanks

arnaudroger commented 4 years ago

Could be possible to get the post process test data bytecode?

gilinykh commented 4 years ago

@arnaudroger Here's a test app sfm-timestamptz-spring.zip

Just run mvn test to get the error (jooq model gets generated by LiquibaseGenerator):

org.jooq.exception.MappingException: Could not find eligible property for 'CREATED_AT' on  class com.example.sfmtimestamptz.TestRepository$TestData not found  See https://github.com/arnaudroger/SimpleFlatMapper/wiki/Errors_PROPERTY_
NOT_FOUND
        at com.example.sfmtimestamptz.SfmTimestamptzSpringApplicationTests.correctOffsetDateTime(SfmTimestamptzSpringApplicationTests.java:24)
mkronberger commented 3 years ago

I have the same issue, with LocalDateTime and Timestamp type. The column in my postgres db has datatype timestamp and i would like to map it to Java LocalDateTime property. Here I also get eligible property for ....

Definition in JOOQ generated table for the column ist: public final TableField<UsersRecord, LocalDateTime> DELETED_DATE;

Its working, if i change the datatype in my java object to Timestamp or String.