queryDsl 查询中的 class 路径是否有限制?

Is there a limit to a class path in a queryDsl query?

我正在使用 QueryDSL 在我的 java 应用程序上构建谓词,似乎使用太大的 class 路径会创建 NullPointerException。 你们中有人遇到过这个问题吗?或者这是正常现象吗?

例如,假设我有 5 个嵌套的 classes (City -> Area -> House -> Room -> Bed) 我想根据该地区的ID。 所以我将使用 :

构建一个 BooleanExpression
public static BooleanExpression areaIdEquals(Long areaId) {
  QBed bed = QBed.bed;
  return bed.room.house.area.id.eq(areaId)
}

这会抛出一个 NullPointerException,因为显然,area 总是空的。

我只想知道这种查询的 class 路径大小有限制是否是常识,因为我发现路径的第 4 个元素始终为 null 很奇怪。我在文档中找不到任何相关信息。

我找到了解释它的 section of the documentation

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.

我使用 QueryInit 测试了解决方案,它有效。