冬眠地图里面的地图

时间:2019-02-27 15:47:00

标签: java hibernate

MappingException:

  

外键(FKosq4t8lua3bsnnh206m2uw3ls:quests_ex   [questRecordEx_id]))的列数必须与   引用的主键(quests_ex [charID,questID])

呼叫者:

@ElementCollection
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@CollectionTable(name = "quests_ex", joinColumns = {@JoinColumn(name = "charID")})
@MapKeyColumn(table = "quests_ex", name = "questID")
private Map<Integer, QuestEx> recordEx;

代码:

@Entity
@Table(name = "quests_ex")
public class QuestEx {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    private int questID;

    @ElementCollection
    @CollectionTable(name = "quests_ex_values")
    @MapKeyColumn(name = "qrkey")
    @Column(name = "qrvalue")
    private Map<String, String> values;
}

SQL:

  create table quests_ex (
    questexid bigint not null auto_increment,
    charid int,
    questID int,
    fk_questid int,
    primary key (questexid),
    foreign key (charid) references characters(id),
    foreign key (fk_questid) references quests_ex_values(id) on delete cascade
);

create table quests_ex_values (
    id bigint not null auto_increment,
    qrkey varchar(255),
    qrvalue varchar(255),
    primary key (id)
);

0 个答案:

没有答案