Spring Boot JPA Lazy Fetch is not working

前端 未结 2 1489
一向
一向 2021-01-19 17:38

I have following two domain objects Suggestion and UserProfile

They are mapped with each other in one to many relationship. When I fetch all suggestions using Spring

2条回答
  •  不知归路
    2021-01-19 17:44

    when you declare fetch = FetchType.LAZY, it means hibernate create a proxy for this field in runtime. when getter of this field is called. the hibernate executes another select to fetch this object. in case of your problem getter of "user" field is called by Jackson (if you use rest). so if you don't want "user", try using a model mapper framework (dozer mapper is a good framework).

提交回复
热议问题