Infinite loop with spring-boot in a one to many relation

前端 未结 6 1853
梦谈多话
梦谈多话 2021-02-06 09:52

In a rest application, I use spring boot with jpa.

I have a class Lodger

who have

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, m         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 10:14

    Do not return entity with circular dependencies via REST webservice - create new DTO class, map entities fetched from database and return it in webservice.

    More info here: http://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application

    Of course if you want you may use another mapping library, my personal favourite is Orika (http://orika-mapper.github.io/orika-docs/intro.html)

提交回复
热议问题