春季Webflux中的嵌套实体
我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论