Java 如何使用QuerydslPredicate按子对象属性筛选?

Java 如何使用QuerydslPredicate按子对象属性筛选?,java,h2,querydsl,Java,H2,Querydsl,我有一个“宠物”域和一个“人”域,一个人可能有一个宠物。在我的RestController上使用querydsldpredicate,我只想返回拥有“DOG”类型宠物的人 Pet.java @实体 公营宠物{ @身份证 @GeneratedValue(策略=GenerationType.IDENTITY) 私人长id; @列(nullable=false) 私有字符串名称; @枚举(EnumType.STRING) @列(nullable=false,name=“animal\u type”)

我有一个“宠物”域和一个“人”域,一个人可能有一个宠物。在我的RestController上使用querydsldpredicate,我只想返回拥有“DOG”类型宠物的人

Pet.java

@实体
公营宠物{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长id;
@列(nullable=false)
私有字符串名称;
@枚举(EnumType.STRING)
@列(nullable=false,name=“animal\u type”)
私有动物型;
//构造函数和getter/setter
}
枚举动物型{
狗,猫
}
Person.java

@实体
公共阶层人士{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长id;
@列(nullable=false)
私有字符串名称;
@列(nullable=false)
私家姓;
@OneToOne(fetch=FetchType.EAGER,cascade=CascadeType.PERSIST)
@JoinColumn(name=“pet_id”)
私人宠物;
//构造函数和getter/setter
}
PersonController.java

@RestController
@请求映射(“人员”)
公共类个人控制器{
@自动连线
个人知识库;
@GetMapping
public List getAll(@querydsldpredicate(root=Person.class)谓词)
{
return(List)personRepository.findAll(谓词);
}
}
PersonRepository.java

公共接口PersonRepository扩展了JpaRepository、QueryDSL谓词执行器{
}
我只想查询有狗的人,他们的GET请求如下:

localhost:8080/人?宠物类型=狗
但这会导致以下错误:

{
    "timestamp": "2019-04-09T18:11:23.430+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Could not access method: Class org.springframework.util.ReflectionUtils can not access a member of class com.example.demo.domain.QPerson with modifiers \"protected\"",
    "path": "/persons"
}
尽管使用
localhost:8080/persons?name=Tom
,查询名为“Tom”的人仍然可以正常工作

我有这个回购协议


我已经尝试了、、和stackoverflow问题的解决方案,但还无法使其起作用。

只需将
pom.xml
中的
querydsl.entityAccessors
属性更改为
false
(或将其删除,默认值为
false

为什么会发生这种情况?

pom.xml
中,您有以下配置:

<querydsl.entityAccessors>true</querydsl.entityAccessors>

只需将
pom.xml
中的
querydsl.entityAccessors
属性更改为
false
(或将其删除,默认值为
false

为什么会发生这种情况?

pom.xml
中,您有以下配置:

<querydsl.entityAccessors>true</querydsl.entityAccessors>