I'm using QueryDSL to build predicates on my java application, and it seems that using a class path that's too big creates a NullPointerException. Has any of you ever had this problem or is this the normal behavior ?
For example, say I have 5 nested classes (City -> Area -> House -> Room -> Bed) and I want to query if a Bed belongs to a certain Area based on the id of that area. So I'll build a BooleanExpression with :
public static BooleanExpression areaIdEquals(Long areaId) {
QBed bed = QBed.bed;
return bed.room.house.area.id.eq(areaId)
}
This throws a NullPointerException because apparently, area is always null.
I just want to know if it's common knowledge that there's a limit to a class path size for this kind of query, because I find it weird that the 4th element of my path is always null. I can't find anything about it in the documentation.
I found the section of the documentation that explains it.
By default Querydsl initializes only reference properties of the first two levels. In cases where longer initialization paths are required, these have to be annotated in the domain types via com.querydsl.core.annotations.QueryInit annotations. QueryInit is used on properties where deep initializations are needed.
I tested the solution using QueryInit and it works.