简体   繁体   English

Spring Data with R2DBC(Mysql) 一对多关联示例

[英]Spring data with R2DBC(Mysql) Example for one to many association

Can I know how to do association(One to Many) in Spring data JDBC with R2DBC(Mysql).Please provide small code example or git link if possible.我可以知道如何在 Spring 数据 JDBC 中使用 R2DBC(Mysql) 进行关联(一对多)。如果可能,请提供小代码示例或 git 链接。

For Example, I have one employee table and address table is child of employee.例如,我有一个员工表,地址表是员工的孩子。 One employee can have multiple addresses.一名员工可以有多个地址。 If I want to retrieve employee, I want address as well to corresponding employee as JSON.如果我想检索员工,我还需要相应员工的地址作为 JSON。 Note: Software stack is Spring Functional Reactive, R2DBC with Mysql注意:软件栈是 Spring Functional Reactive,R2DBC with Mysql

Spring Data R2DBC currently does not support aggregates. Spring Data R2DBC 目前不支持聚合。 This means every entity gets mapped to just one table and can't have object references to other entities.这意味着每个实体都只映射到一个表,并且不能有对其他实体的对象引用。

Therefore the correct way to model your example is to have no object reference between Empolyee and Address but have an employeeId in the Address and use that to select the desired addresses.因此,为您的示例建模的正确方法是在EmpolyeeAddress之间没有对象引用,但在Address有一个employeeId并使用它来选择所需的地址。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM