Hi, thanks for the response!
I had tried making a converter but it isn't working. I still get the same
error. Might you have any idea what I'm doing wrong? Is there something
specific I have to do to get it to trigger? I did a maven build again to
regenerate the sources. Do I need to change the query somehow or is there
something else I'm missing or have done wrong? Thanks for any input.
*My pom.xml:*
<generator>
<database>
<name>org.jooq.util.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes />
<inputSchema>public</inputSchema>
<forcedTypes>
<forcedType>
<userType>java.time.ZonedDateTime</userType>
<converter>com.foo.domain.util.ZonedDateTimeConverter</converter>
<expression>.*</expression>
<types>TIMESTAMP</types>
</forcedType>
</forcedTypes>
</database>
<target>
<packageName>com.foo.jooq</packageName>
<directory>target/generated-sources</directory>
</target>
</generator>
*My ZonedDateTimeConverter.java converter implementation:*
public class ZonedDateTimeConverter implements Converter<Long,
ZonedDateTime> {
@Override
public ZonedDateTime from(Long aLong) {
Instant instant = Instant.ofEpochSecond(aLong);
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant,
ZoneId.systemDefault());
return zonedDateTime;
}
@Override
public Long to(ZonedDateTime zonedDateTime) {
return zonedDateTime.toEpochSecond();
}
@Override
public Class<Long> fromType() {
return Long.class;
}
@Override
public Class<ZonedDateTime> toType() {
return ZonedDateTime.class;
}
}
On Friday, November 18, 2016 at 4:21:12 AM UTC-5, Patryk Najda wrote:
>
> Hi,
>
> it seems like you're missing a converter which would convert from the type
> which is stored in your DB (from it's value (1479365948726)I guess it's a
> TIMESTAMP)
> to a type which is used in your POJO (ZonedDateTime).
>
> Please have a look at this article regarding Converters:
> http://www.jooq.org/doc/2.6/manual/sql-execution/fetching/data-type-conversion/
>
> Let me know if this helped you.
>
>
>
> W dniu piątek, 18 listopada 2016 09:53:58 UTC+1 użytkownik
> [email protected] napisał:
>>
>> Hi,
>>
>> I'm trying to run a simple select like so:
>>
>> List<Foo> foos = create.select()
>> .from(FOO)
>> .limit(pageable.getPageSize())
>> .offset(pageable.getOffset())
>> .fetchInto(Foo.class);
>>
>>
>>
>> I'm getting this error:
>>
>>
>> org.jooq.exception.MappingException: An error ocurred when mapping record to
>> class Foo
>> at
>> org.jooq.impl.DefaultRecordMapper$MutablePOJOMapper.map(DefaultRecordMapper.java:658)
>>
>> ...
>>
>> Caused by: org.jooq.exception.DataTypeException: Cannot convert from
>> 1479365948726 (class java.lang.Long) to class java.time.ZonedDateTime
>> at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:1118)
>> at org.jooq.tools.Convert$ConvertAll.toDate(Convert.java:1070)
>> at org.jooq.tools.Convert$ConvertAll.from(Convert.java:789)
>> at org.jooq.tools.Convert.convert0(Convert.java:316)
>> at org.jooq.tools.Convert.convert(Convert.java:308)
>> at org.jooq.tools.Convert.convert(Convert.java:380)
>> at org.jooq.impl.AbstractRecord.get(AbstractRecord.java:243)
>> at
>> org.jooq.impl.DefaultRecordMapper$MutablePOJOMapper.map(DefaultRecordMapper.java:694)
>> at
>> org.jooq.impl.DefaultRecordMapper$MutablePOJOMapper.map(DefaultRecordMapper.java:614)
>>
>>
>> I'm using jooq 3.8.6 with a postgresql database. Does anyone have any
>> ideas why? My Foo.java entity does have some ZonedDateTime fields. I'm
>> guessing jooq doesn't support these? If that's the case, which date/time
>> type should I be using?
>>
>
--
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.