春季Webflux中的嵌套实体

发布于 2025-01-27 22:54:01 字数 1164 浏览 4 评论 0原文

我正在尝试在Spring Webflux中使用嵌套实体。 我有一个对象用户:

@Table
public class User {

    @Id private Long id;
    private String firstname;
    private String lastname;

    ...getters, setters, constructors
}

一个对象出版物:

@Table
public class Publication {

    @Id private Long id;
    private User publisher;
    private String title;
    private String body;

    ...getters, setters, constructors
}

我正在成功地与用户检索出版物:

    {
    "id": 1,
    "publisher": {
      "id": 1,
      "firstname": "John",
      "lastname": "Smith"
    }
    "title": "A title",
    "body": "A body"
    }

我希望在创建新出版物时能够发布相同的对象,但是当我这样做时,我会遇到错误:

Nested entities are not supported.

我的PublicationRepository:

@Repository
public interface PublicationRepository extends ReactiveCrudRepository<Publication, Long> {
}

PublicationService保存:

public Mono<Publication> savePublication(Publication publication) {
  return publicationRepository.save(publication);
}

我可以简单地将用户更改为出版物中的用户,但这意味着为每个出版物的用户表向用户表提出了新的请求。

I am trying to use nested entities in spring webflux.
I have an object User :

@Table
public class User {

    @Id private Long id;
    private String firstname;
    private String lastname;

    ...getters, setters, constructors
}

And an object Publication :

@Table
public class Publication {

    @Id private Long id;
    private User publisher;
    private String title;
    private String body;

    ...getters, setters, constructors
}

I am successfully retrieving publications with their users as follow :

    {
    "id": 1,
    "publisher": {
      "id": 1,
      "firstname": "John",
      "lastname": "Smith"
    }
    "title": "A title",
    "body": "A body"
    }

I would like to be able to post the same object when creating a new Publication, but when I do so, I am getting the error :

Nested entities are not supported.

My PublicationRepository :

@Repository
public interface PublicationRepository extends ReactiveCrudRepository<Publication, Long> {
}

PublicationService save :

public Mono<Publication> savePublication(Publication publication) {
  return publicationRepository.save(publication);
}

I could simply change user to userId in Publication, but that would imply making a new request to users table for each publication retreived.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文