简体   繁体   English

SpringBoot Hibernate。 无法在 Postman、Swager、api 链接中获取用于 OneToMany、ManyToOne 关系的 findAll 和 findById

[英]SpringBoot Hibernate. Unable to GET findAll and findById in Postman, Swager, api link for OneToMany, ManyToOne relationship

I'm unable to get response in Postman.我无法在 Postman 中得到响应。 It becomes an infinite loop I think.我认为它变成了一个无限循环。 The models are: dish, category.模型有:菜、类。 One category had multiple dishes.一类有多种菜肴。 在此处输入图像描述

Before add Dish (id, category), it behave normal like this在添加 Dish (id, category) 之前,它的行为正常是这样的在此处输入图像描述 Here is the Dish and Category model这是菜和类别 model 在此处输入图像描述 在此处输入图像描述 Here is one of the Controller这是 Controller 之一在此处输入图像描述 The post dish working great, but the search is not.后菜效果很好,但搜索却不行。 Anyone know how to solve it?有谁知道如何解决它? (The db I use is Postgres) (我使用的数据库是 Postgres)

Edit: I solved it.编辑:我解决了。 Using @JsonBackReference and @JsonManageReference使用 @JsonBackReference 和 @JsonManageReference

Your Dish & Category are related entities.您的菜肴和类别是相关实体。

Try having @JsonIgnore annotation in your Dish class for Category field or the other way around.尝试在您的 Dish class 中为 Category 字段添加 @JsonIgnore注释,反之亦然。

Also, always use a DTO instead of returning the actual DB object in the Rest-call.此外,始终使用 DTO 而不是在 Rest-call 中返回实际的 DB object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate中的Order和OrderLine Relationship映射。 在哪里放置@OnetoMany和/或@ManytoOne - Order and OrderLine Relationship mapping in Hibernate. Where to put @OnetoMany and/or @ManytoOne OneToMany / ManyToOne关系的Hibernate标准 - Hibernate criteria for OneToMany/ManyToOne relationship OneToMany 映射在 findById/findAll 期间生成错误的休眠 SQL - OneToMany mapping generates the wrong hibernate SQL during findById/findAll 休眠@OneToMany和@ManyToOne关系错误 - Hibernate @OneToMany and @ManyToOne relationship works wrong 无法使用 OneToMany 和 ManyToOne 关系在 hibernate 中创建表(也无法创建外键) - Unable to create a table in hibernate using OneToMany and ManyToOne relationship(also unable to create Foreign Key) 使用JPA(hibernate)和简单的oneToMany无法持久保存新的对象图 - ManyToOne关系 - Unable to persist new object graph using JPA (hibernate) with simple oneToMany - ManyToOne relationship JPA/Hibernate/SpringBoot:插入@OneToMany 关系实体 - JPA/Hibernate/SpringBoot: Inserting @OneToMany relationship entities 无法在HIbernate 4中保持OneToMany关系 - Unable to persist OneToMany relationship in HIbernate 4 休眠onetomany多音问题 - Hibernate onetomany manytoone issue 休眠@OneToMany @ManyToOne映射 - Hibernate @OneToMany @ManyToOne mapping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM