2

I have a hashmap:

Map<String, String> map = new HashMap<String, String>

I would like to map keys and values of hashmap to table's column. For example, if I have something like this: (key1, value1); (key2, value2), the table will look like:

id  key  value
1   key1 value1
2   key2 value2.

I've tried use something like this in my model class

@ElementCollection
@MapKeyColumn(name = "property")
@Column(name = "value", nullable = false)
private Map<String, String> settings = new HashMap<String, String>();

but it couses that hibernate creates two tables: first one with one column: id, second one with three columns id_table (foreign key to id from first column), key, value.

I will be grateful for any help.

Marcin
  • 508
  • 2
  • 10
  • 28
  • 1
    [see if this can help](http://stackoverflow.com/questions/3393649/storing-a-mapstring-string-using-jpa) – Ori Dar Sep 16 '13 at 23:00
  • Can you show the containing entity? – David Levesque Sep 16 '13 at 23:48
  • `I would like to map keys and values of hashmap to table's column`... I still don't understand what is what you are trying to accomplish. Do you want the foreign key of the child/collection table to be an arbitrary unique column of the parent table? – mess Sep 17 '13 at 03:29
  • @orid: thank you. I was looking for something like this. – Marcin Sep 17 '13 at 08:03

0 Answers0