@ManyToOne 和@OneToMany 在通过 profileRepository.getByProfileId(id) 检索时以无限循环结束;

@ManyToOne and @OneToMany ends up in unlimited loop when retrieved through profileRepository.getByProfileId(id);

Class Jobs 与 Profile 具有多对一关系。 当我通过 profileRepository.getByProfileId(id) 检索响应 returns 递归数据时。 此外,如果您注意到 Profile 具有 Login 对象。我也不想 return。

@Entity
@Table(name = "tbl_profile")
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class Profile {

    @Id
    @Column(name = "profile_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    long profileId;

    @NonNull
    @Column(name = "name")
    String name;

    @Column(name = "description", nullable = false)
    String description;

    @OneToOne
    @JoinColumn(name = "login_id",
                referencedColumnName = "login_id")
    Login login;

    @OneToMany(
            mappedBy = "profile"
    )
    List<Jobs> job;

Class 职位

@Entity
@Table(name = "tbl_job")
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class Jobs {

    @Id
    @Column(name = "job_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    long jobId;

    @NonNull
    @Column(name = "job_role", nullable = false)
    String joRole;

    @Column(name = "description", nullable = false)
    String description;

    @ManyToOne
    @JoinColumn(name = "profile_id",
                referencedColumnName = "profile_id")
    Profile profile;
}

对 属性 使用 @JsonIgnore 以忽略 JSON 上的输出。同样根据你的业务逻辑,重新检查是否需要双向关联。您可以只添加单向关联。