Jackson bidirectional relationship (One-to-many) not working

后端 未结 3 1346
半阙折子戏
半阙折子戏 2021-01-14 07:48

I\'m using Spring(xml+annotations), Hibernate(annotations) in this web service project. The database relationship diagram, models, expected and actual output are given below

3条回答
  •  星月不相逢
    2021-01-14 08:06

    This seems pretty old but let me put my coins here as well; I would seperate the entity and model. Means;

    > Client <-> Application : Models
    > 
    > Application <-> Database : Entities
    

    And your service layer or whatever layer you process data should make the conversion between entities and models.

    1. You get rid of recursion by returning data as your wish.
    2. You split the definitions between two different communication channels. This way you can decide what to show to your client and how to show your client as well. This will save your DB schema be exposed directly too.
    3. You can extend model as per your wish without touching to the DB backend.

提交回复
热议问题