Spring Data MongoDB 无法加载参考集合(@DocumentReference)
在 Spring 数据中 findAll 方法引用对象为 null
我正在使用 Reactive Mongo Repository
Ex 父对象
@Data
@Document(collection = "country")
public class CountryBean {
@Id
private String id;
private String name;
}
子对象
@Document(collection = "city")
public class CityBean {
@Id
private String id;
@Field(name = "name")
private String name;
@Field(name = "city_code")
private String cityCode;
@Field(name = "show_city")
private boolean showCity;
@DocumentReference(lazy = false)
private StateBean state;
}
国家集合(在这里我们可以看到国家属性)
但是当尝试从数据库获取时,我得到的国家/地区属性为空。尝试了惰性真/假,但没有获取国家对象和状态对象。
@GetMapping("/get-all-state")
Flux<StateBean> allState() {
Flux<CountryBean> ct = countryRepository.findAll();
Flux<StateBean> bean= stateRepository.findByCountry(ct.blockFirst());
return bean;
}
[{"id":"6237a912850ceb6261998a53","name":"Bangalore","statecode":"39","country":null},{"id":"6237a94a850ceb6261998a55","name":"delhi","statecode":"39","country":null}]
In Spring data findAll method reference object is coming as null
I am using Reactive Mongo Repository
Ex Parent Object
@Data
@Document(collection = "country")
public class CountryBean {
@Id
private String id;
private String name;
}
Child Object
@Document(collection = "city")
public class CityBean {
@Id
private String id;
@Field(name = "name")
private String name;
@Field(name = "city_code")
private String cityCode;
@Field(name = "show_city")
private boolean showCity;
@DocumentReference(lazy = false)
private StateBean state;
}
State Collection (Here we can see the country Attribute)
But When trying to fetch from DB, I am getting country attribute as null. Tried both lazy true/false, but not getting country object along with state object.
@GetMapping("/get-all-state")
Flux<StateBean> allState() {
Flux<CountryBean> ct = countryRepository.findAll();
Flux<StateBean> bean= stateRepository.findByCountry(ct.blockFirst());
return bean;
}
[{"id":"6237a912850ceb6261998a53","name":"Bangalore","statecode":"39","country":null},{"id":"6237a94a850ceb6261998a55","name":"delhi","statecode":"39","country":null}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,使用反应式基础设施时不支持@DocumentReference。引用自 文档:
Unfortunately there is no support for @DocumentReference when using reactive infrastructure. A quote from the documentation: