Joda converter DataTypeException fetching into POJO

212 views
Skip to first unread message

ma...@excellclan.com

unread,
Jan 3, 2015, 11:28:01 PM1/3/15
to jooq...@googlegroups.com
First off, I'm fairly new to jOOQ - and I have to say that I'm really impressed with what I'm finding. Great stuff!

I am using version 3.5.1 on Java 7. 

I have several fields in a Postgres db that are timestamps. I use Joda in the business code, so part of bringing jOOQ into this project was adding a converter like in the docs:

public class JooqJodaDateTimeConvertor implements Converter<Timestamp, DateTime> {

 
@Override
 
public DateTime from(Timestamp databaseObject) {
   
if (databaseObject == null) {
       
return null;
   
}
   
return new DateTime(databaseObject.getTime());
 
}

 
@Override
 
public Timestamp to(DateTime dt) {
   
if (dt == null) {
       
return null;
   
}
   
return new Timestamp(dt.getMillis());
 
}

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

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

This appears to work perfectly for record objects - I can pull records from the database and get the contents of those fields without any issue - types are correct, etc.

The issue appears when I try to fetch into a generated pojo. The types on the pojo appear fine. For example:

private org.joda.time.DateTime createdAt;

[...]

@javax.validation.constraints.NotNull
public org.joda.time.DateTime getCreatedAt() {
   
return this.createdAt;
}

public void setCreatedAt(org.joda.time.DateTime createdAt) {
   
this.createdAt = createdAt;
}


But when I execute the following (I'm getting the field name from the user, in truth - which is why I'm putting in a String here, by the way):

create.fetchOne(t, t.field("id").equal(id)).into(Test.class)

I get the following exception:

org.jooq.exception.MappingException: An error ocurred when mapping record to class com.fluidapps.model.bootstrap.tables.pojos.Instance
        at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76) [resteasy-jaxrs-3.0.8.Final.ja
r:]
        at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) [resteasy-jaxrs-3.0.8.Final.jar:]
        at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149) [resteasy-jaxrs-3.0.8.Final.jar
:]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) [resteasy-jaxrs-3.0.8.Final.jar:]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.8.Final.jar:] 
        [more jboss references removed . . . ]
Caused by: javax.ejb.EJBException: org.jooq.exception.MappingException: An error ocurred when mapping record to class com.fluidapps.model.bootstrap.tables.pojos.Instance
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.
Final]
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:369) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:241) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        [more jboss references removed . . . ]
Caused by: org.jooq.exception.MappingException: An error ocurred when mapping record to class com.fluidapps.model.bootstrap.tables.pojos.Instance
        at org.jooq.impl.DefaultRecordMapper$MutablePOJOMapper.map(DefaultRecordMapper.java:493) [jooq-3.5.1.jar:]
        at org.jooq.impl.DefaultRecordMapper.map(DefaultRecordMapper.java:331) [jooq-3.5.1.jar:]
        at org.jooq.impl.AbstractRecord.into(AbstractRecord.java:669) [jooq-3.5.1.jar:]
        at com.fluidapps.enterprise.services.EntityService.findAndFillJooqEntity(EntityService.java:1133) [FluidAppsManager-model.jar:]
        at com.fluidapps.enterprise.services.EntityService.findAndFillJooqEntity(EntityService.java:1089) [FluidAppsManager-model.jar:]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_10]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_10]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_10]
        at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_10]
        at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
        at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
        [more jboss references removed . . . ]
Caused by: org.jooq.exception.DataTypeException: Cannot convert from 2013-09-20T16:50:47.820Z (class org.joda.time.DateTime) to class java.util.Date
        at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:873) [jooq-3.5.1.jar:]
        at org.jooq.tools.Convert$ConvertAll.from(Convert.java:811) [jooq-3.5.1.jar:]
        at org.jooq.tools.Convert.convert0(Convert.java:300) [jooq-3.5.1.jar:]
        at org.jooq.tools.Convert.convert(Convert.java:292) [jooq-3.5.1.jar:]
        at org.jooq.tools.Convert.convert(Convert.java:360) [jooq-3.5.1.jar:]
        at org.jooq.impl.AbstractRecord.getValue(AbstractRecord.java:253) [jooq-3.5.1.jar:]
        at org.jooq.impl.DefaultRecordMapper$MutablePOJOMapper.map(DefaultRecordMapper.java:486) [jooq-3.5.1.jar:]
        ... 114 more

All the caused-bys are due to layers it bubbles up through, of course - I would expect that the important parts should be the last 2.

I have searched the jOOQ site, Googled for anything that might solve this, searched StackOverflow and this user group to no avail.

I have probably just missed something in my setup of the generator or something. Please, can anybody help me work through this?

Lukas Eder

unread,
Jan 4, 2015, 3:55:09 AM1/4/15
to jooq...@googlegroups.com
Hi Matt,

2015-01-04 5:28 GMT+01:00 <ma...@excellclan.com>:
First off, I'm fairly new to jOOQ - and I have to say that I'm really impressed with what I'm finding. Great stuff!

Thanks for your nice words!
 
But when I execute the following (I'm getting the field name from the user, in truth - which is why I'm putting in a String here, by the way):

create.fetchOne(t, t.field("id").equal(id)).into(Test.class)

Just to be sure: What is this "t"? Is it the generated table that contains Field references that refer to your converter?
 
I get the following exception:

[...]
Caused by: org.jooq.exception.DataTypeException: Cannot convert from 2013-09-20T16:50:47.820Z (class org.joda.time.DateTime) to class java.util.Date
        at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:873) [jooq-3.5.1.jar:]
        at org.jooq.tools.Convert$ConvertAll.from(Convert.java:811) [jooq-3.5.1.jar:]


Where does this java.util.Date come from? jOOQ doesn't know how to convert from Joda's DateTime to java.util.Date...

Cheers,
Lukas

Matthew Excell

unread,
Jan 4, 2015, 2:26:06 PM1/4/15
to jooq...@googlegroups.com


On Sunday, January 4, 2015 1:55:09 AM UTC-7, Lukas Eder wrote:
Hi Matt,

2015-01-04 5:28 GMT+01:00 <ma...@excellclan.com>:
First off, I'm fairly new to jOOQ - and I have to say that I'm really impressed with what I'm finding. Great stuff!

Thanks for your nice words!
 
But when I execute the following (I'm getting the field name from the user, in truth - which is why I'm putting in a String here, by the way):

create.fetchOne(t, t.field("id").equal(id)).into(Test.class)

Just to be sure: What is this "t"? Is it the generated table that contains Field references that refer to your converter?
 

It is a reference to the generated table, yes.
 
I get the following exception:

[...]
Caused by: org.jooq.exception.DataTypeException: Cannot convert from 2013-09-20T16:50:47.820Z (class org.joda.time.DateTime) to class java.util.Date
        at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:873) [jooq-3.5.1.jar:]
        at org.jooq.tools.Convert$ConvertAll.from(Convert.java:811) [jooq-3.5.1.jar:]


Where does this java.util.Date come from? jOOQ doesn't know how to convert from Joda's DateTime to java.util.Date...

And that was the clue I needed - thank you! A search turned up a superclass which had some vestigial code from before jOOQ (that used java.util.Date). Removed that code and it worked immediately.

Thanks!

Matt
 

Cheers,
Lukas
Reply all
Reply to author
Forward
0 new messages