我正在做一个食品卡车 API,只是为了学习 spring-boot。在做的过程中,遇到了关于注释 @Manytomany 如何工作的问题。
因为这个项目只是为了学习我想使用Google CLoud Firestore,所以我知道NoSql数据库对于这个建议绝对不是最好的选择。所以我的数据库是新的且空的,如果在两个模型中都引用其他内容,我将如何插入一些内容
成分型号:
@ManyToMany
@JoinTable(name = "ingredientLunch", joinColumns = @JoinColumn(name = "lunch"), inverseJoinColumns =
@JoinColumn(name = "ingredient"))
private List<Lunch> lunch = new ArrayList<>();
午餐模型:
@ManyToMany(mappedBy = "lunch")
private List<Ingredient> ingredients = new ArrayList<>();
它是如何工作的?另外,我对带有 spring-boot 的 Google Cloud Firestore 一无所知,我还需要什么来进行集成。还有一个问题,JPA 是在行业之外使用的吗?我可以将 Google Cloud Firestore 与 JPA 结合使用吗?也许我对什么是 JPA 有点困惑。
最佳答案
目前 Google Cloud Firestore 没有 JPA 实现。您最好的两个选择是:
- 代替 JPA 切换到类似的东西,例如 https://catatumbo.io/
- 使用 Google Cloud Spanner 等理性数据库,该数据库有 JPA 实现。
为了方便地讨论 @ManyToMany
在 JPA 中的工作方式,这本 Wikibook 是一个很好的资源:https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany
关于java - 我如何处理JPA注释@ManytoMany,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55942695/