我有一个实体MorningMinutesNote,它使用连接表morning_minutes_note_item_type与MorningMinutesNoteType具有@ManyToMany关系。
@Entity
@Table(name = "morning_minutes_note", schema = "public")
public class MorningMinutesNote {
private List<MorningMinutesNoteType> itemTypes = new ArrayList<MorningMinutesNoteType>();
@ManyToMany
@JoinTable(name="morning_minutes_note_item_type",
joinColumns=@JoinColumn(name="morning_minutes_note_id",updatable=false,insertable=false),
inverseJoinColumns=@JoinColumn(name="item_type_id",updatable=false,insertable=false))
public List<MorningMinutesNoteType> getItemTypes() {
return itemTypes;
}
<小时/>
CREATE TABLE morning_minutes_note_item_type(
morning_minutes_note_item_type_id BIGINT PRIMARY KEY DEFAULT NEXTVAL('morning_minutes_note_item_type_id_seq'),
morning_minutes_note_id BIGINT NOT NULL,
item_type_id BIGINT NOT NULL
);
我创建了一个 View 表view_morning_minutes_note,它使用morning_minutes_note作为主表。如何引用 MorningMinutesNoteType 列表 也到 View 表,以便我也可以从 ViewMorningMinutesNote 获取列表。我不知道这是否可能,但我尝试添加 MorningMinutesNote 的确切注释 到 ViewMorningMinutesNote 但它没有获取任何内容。
@Entity
@org.hibernate.annotations.Entity(selectBeforeUpdate = false,dynamicInsert = true, dynamicUpdate = true)
@Table(name = "view_morning_minutes_note", schema = "public")
public class ViewMorningMinutesNote{
private List<MorningMinutesNoteType> itemTypes = new ArrayList<>();
最佳答案
如果您需要直接访问JoinTable
,您可以使用FluentJPA能够公开 join table for queries .
关于java - 将连接表引用到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58448958/