0

How to create a hashmap with 2 foreign keys as reference? Something like, Table 3 have a hashmap that for each table1 id have an id from table2.

@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;
...

I was trying something like this:

@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>();
...
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Xplouder
  • 148
  • 1
  • 4
  • 13
  • Don't understand what you want to get at the end. But most probably defining the relation in table1 and table2 should give you the expected behavior. http://docs.oracle.com/javaee/6/tutorial/doc/bnbqa.html#bnbqh – SubOptimal Oct 27 '14 at 12:47
  • Imagine a Shop as table3, Product as table1 and Supplier as table2. So, for each Shop instance i want a hashmap with **Product ID** as key and the respective value with **Supplier(s) ID**. – Xplouder Oct 27 '14 at 14:35
  • What is the criteria to differentiate the product/supplier belonging to the different shops? – SubOptimal Oct 28 '14 at 07:51
  • Each product is unique in each shop but a supplier can be for N shops. Also "shops" are all of the same type, i mean they sells the same products. Like an group of shops. – Xplouder Oct 30 '14 at 09:54

0 Answers0