I have a simple PostgreSQL table:
CREATE TABLE public.test_entity (
id int8 NOT NULL,
title varchar NOT NULL,
created_at date NOT NULL,
CONSTRAINT test_entity_pkey PRIMARY KEY (id)
);
Entity for that table and DTO:
@Entity
@Table(name = "test_entity")
@Getter
@Setter
@ToString
public class TestEntity {
@Id
@Column(name = "id")
private Long id;
@Column(name = "title")
private String title;
@Column(name = "created_at")
private LocalDate createdAt;
...equals and hashcode...
}
@Data
public class TestEntityDto {
private Long id;
private String title;
private LocalDate createdAt;
}
All builds fine and after build I have QTestEntity class:
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QTestEntity extends EntityPathBase<TestEntity> {
private static final long serialVersionUID = -1443624162L;
public static final QTestEntity testEntity = new QTestEntity("testEntity");
public final DatePath<java.time.LocalDate> createdAt = createDate("createdAt", java.time.LocalDate.class);
public final NumberPath<Long> id = createNumber("id", Long.class);
public final StringPath title = createString("title");
public QTestEntity(String variable) {
super(TestEntity.class, forVariable(variable));
}
public QTestEntity(Path<? extends TestEntity> path) {
super(path.getType(), path.getMetadata());
}
public QTestEntity(PathMetadata metadata) {
super(TestEntity.class, metadata);
}
}
Then I try a simple select query:
final QTestEntity qTestEntity = QTestEntity.testEntity;
final JPASQLQuery<TestEntityDto> query = new JPASQLQuery<>(this.db.getEntityManager(), new PostgreSQLTemplates())
.select(Projections.bean(TestEntityDto.class,
qTestEntity.id,
qTestEntity.title,
qTestEntity.createdAt))
.from(qTestEntity);
final List<TestEntityDto> rows = query.fetch();
And it throw exception java.lang.IllegalArgumentException: argument type mismatch:
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.querydsl.core.types.QBean.newInstance(QBean.java:239)
at com.querydsl.core.support.NumberConversions.newInstance(NumberConversions.java:86)
at com.querydsl.jpa.FactoryExpressionTransformer.transformTuple(FactoryExpressionTransformer.java:51)
at org.hibernate.hql.internal.HolderInstantiator.instantiate(HolderInstantiator.java:85)
at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:433)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2682)
at org.hibernate.loader.Loader.list(Loader.java:2677)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2186)
at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1204)
at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:177)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
at org.hibernate.query.Query.getResultList(Query.java:165)
at com.querydsl.jpa.sql.AbstractJPASQLQuery.getResultList(AbstractJPASQLQuery.java:203)
at com.querydsl.jpa.sql.AbstractJPASQLQuery.fetch(AbstractJPASQLQuery.java:235)
Debugger shows that type of createdAt field is java.sql.Date instead of LocalDate.
I found this question (Why does Querydsl not translate java.time.* columns when in an shaded jar?) and check in debugger that JSR310 types loads fine in JavaTypeMapping.
Is this a bug in QueryDSL or I do something wrong?
Spring Boot 2.6, QueryDSL 5.0.0, Hibernate 5.6.9