JPA-具有联接表但缺少目标表的多对多映射

问题描述

我正在使用具有以下2个表的第三方数据库

Instrument
------
id (pk int not null)
name

InstrumentGroup
------
groupName (pk varchar(25) not null)
instrumentId (pk fk int not null)

如何定义具有InstrumentGroup集合的Group(或定义Instrument)实体?注意:该数据库没有Group表`。我目前有:

@Entity
@Data
public class InstrumentGroup {
  
  @EmbeddedId
  private InstrumentGroupKey instrumentGroupKey;
}

@Embeddable
@Data
public class InstrumentGroupKey implements Serializable {
   
   private String groupName;
   
   @ManyToOne
   @JoinColumn(name = "instrumentId")
   private Instrument instrument;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)