2017-12-13 20 views
0

java-1.8 jooq-3.10.0 SpringBoot-1.5.7는 ZonedDateTime 필드 DataTypeException

myCondition = create .select(... TABLE_AL.START_DATE.as("table_al_start_date"), TABLE_BR.START_DATE.as("table_br_start_date"))) .from(MAIN).innerJoin(TABLE_AL).onkey() .innerJoin(TABLE_BR).onkey() .where(DSL.trueCondition()); List<MyObject> myObjList = myCondition.fetch().into(MyObject.class)

class MyObject(){ ZonedDateTime tableAlStartDate; ZonedDateTime tableBrStartDate; ... }

table_al_start_datejava.time.ZonedDateTime 내 개체 여러 테이블에서 필드가

, PostgreSQL에서 timestamp without time zone,nullable,

을 충족 데이터 형식 예외가 발생합니다. rown 사용 .select(TABLE_A.START_DATE.as("table_a_start_date").cast(ZonedDateTime.class) 도 세터 setTableAlStartDate(Long long)를 추가하려고 org.jooq.exception.SQLDialectNotSupportedException: Type class java.time.ZonedDateTime is not supported in dialect null

을 만난 것 MyObject Caused by: org.jooq.exception.DataTypeException: Cannot convert from 1511971200000 (class java.lang.Long) to class java.time.ZonedDateTime at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:1169) at org.jooq.tools.Convert$ConvertAll.toDate(Convert.java:1121) at org.jooq.tools.Convert$ConvertAll.from(Convert.java:823)

경우에 가져올 때 작동하지 않습니다.

custom-bindings에서 변환기를 찾았습니까? 사용자 지정 변환기를 만든 후에 무엇을해야합니까? DataType<LocalDate> type = SQLDataType.DATE.asConvertedDataType(new LocalDateConverter());은 어디입니까?

ZonedDateTime 필드와 어떤 관계가 있습니까? 감사합니다. . 이 좋은 연습하면

답변

0

확실하지, 나를 위해 작동 :

myCondition = create 
    .select(,,, 
     DSL.field("table_al.start_date", SQLDataType.TIMESTAMP 
      .asConvertedDataType(ts2zonedConverter)) 
      .as("table_al_start_date"),,,, 
    .from(,,,); 

myConverter

public class TsZonedDateTimeConverter implements Converter<Timestamp, ZonedDateTime> { 
@Override public ZonedDateTime from(Timestamp t) { 
     return t == null ? null : t.toInstant().atZone(ZoneId.of("UTC")); 
    } 
@Override public Timestamp to(ZonedDateTime u) { 
     return u == null ? null : Timestamp.from(u.toInstant()); 
    } 
}