带有2个外键的Hashmap

时间:2014-10-27 11:52:59

标签: jpa hashmap foreign-keys mapkeyjoincolumn

如何创建一个带有2个外键作为参考的hashmap?表3中有一个散列图,每个table1 id都有一个来自table2的id。

@Entity
public class table1 implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...

@Entity
public class table2 implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...

我正在尝试这样的事情:

@Entity
public class table3 implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;

@ElementCollection
@MapKeyJoinColumn(name = "table1", referencedColumnName = "ID")
@MapKeyJoinColumn(name = "table2", referencedColumnName = "ID")
private Map<table1, table2> hashmap_relation = new LinkedHashMap<table1, table2>();
...

0 个答案:

没有答案