Hi,
I'm trying to use Projections.bean() to convert the result from a simple select query to a DTO (SomeObject class) but I'm getting the following error when dealing with Java 8 OffsetDateTime properties:
java.sql.Timestamp is not compatible with java.time.OffsetDateTime
The SomeObject class looks like this (other properties omitted for the sake of clarity):
public class SomeObject {
private String id;
private OffsetDateTime expiresOn;
// getters and setters omitted
}
Generating the Q classes directly from JDBC metadata results in a
QSomeObject class containing the
expiresOn property as Timestamp (as expected):
public class QSomeObject extends com.querydsl.sql.RelationalPathBase<QSomeObject> {
...
public final DateTimePath<java.sql.Timestamp> expiresOn = createDateTime("expiresOn", java.sql.Timestamp.class);
...
}
The code that performs the select query:
static final QSomeObject qSomeObject = QSomeObject.someObject;
static final QBean<SomeObject> bean = Projections.bean(SomeObject.class, qSomeObject.id, qSomeObject.expiresOn);
public SomeObject find(String someId) {
return sqlQueryFactory.select(bean)
.from(qSomeObject)
.where(qSomeObject.id.eq(someId))
.fetchOne();
}
Any idea what I might be missing here?
Is there any built-in mechanism to convert from Timestamp to OffsetDateTime? If not, is there any convenient way to do it manually?
Cheers,
Bruno