简体   繁体   English

springboot中可以实现这样的数据库结构吗?

[英]Is it possible to implement such a database structure in springboot?

I use hibernate as the framework for springboot CUBA operations.我使用hibernate作为springboot CUBA操作的框架。 But I have a problem, our workout information and recipe information are coming from external API.但是我有一个问题,我们的锻炼信息和食谱信息来自外部 API。 This means that I only need to store the recipe and workout ids in the database.这意味着我只需要在数据库中存储配方和锻炼 ID。 The database structure is as follows.数据库结构如下。 DB sturucture数据库结构

As the data is provided by the API, we have not created corresponding entity tables for workouts and recipes.由于数据是由 API 提供的,我们没有为锻炼和食谱创建相应的实体表。 But then the problem arises.但随后问题就来了。 What should be done with the join table in this case.在这种情况下应该对连接表做什么。 I mean the premise of @manytomany is that two entity tables are needed, and we only have entity tables for users.我的意思是@manytomany的前提是需要两个实体表,我们只有用户实体表。 Even if we use a joint primary key, there is still a need to add user_id as a foreign key in the joint primary key.即使我们使用了联合主键,仍然需要在联合主键中添加 user_id 作为外键。 How can we mark user_id as a foreign key without a workout or recipe entity table?我们如何在没有锻炼或配方实体表的情况下将 user_id 标记为外键?

Your question is quite confusing but I'll try to provide an answer for what I understood.你的问题很令人困惑,但我会尽力为我的理解提供答案。

If the data is completely external, you can map an element collection consisting of ids only:如果数据完全是外部的,您可以映射一个仅由 id 组成的元素集合:

@Entity
public class User {
  // other fields
  @ElementCollection
  @CollectionTable(name = "recipse_user")
  Set<Long> recipeIds;
  @ElementCollection
  @CollectionTable(name = "workout_user")
  Set<Long> workoutIds;
}

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

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