I’m trying to get a list of multiple columns from my table using QueryDSL, and automatically fill my DB object, like this example in an older manual:
List<CatDTO> catDTOs = query.from(cat)
.list(EConstructor.create(CatDTO.class, cat.id, cat.name));
The problem is that it looks like the EConstructor class was removed in version 2.2.0, and all the examples I find now are like this:
List<Object[]> rows = query.from(cat)
.list(cat.id, cat.name);
Which forces me to manually cast all the objects into my CatDTO class.
Is there any alternative to this? Any EConstructor alternative?
EConstructor has been replaced with ConstructorExpression in Querydsl 2.0. So your example would become
You can also annotate the CatDTO constructor and query like this
Alternatively you can use the QTuple projection which provides a more generic access option
The actual values can be accessed via their path like this
and
Tuple projection will probably be used in Querydsl 3.0 for multiple columns projections instead of Object arrays.