Reputation: 6442
I have the following database structure:
Table 1 Table 2
Table 3
tid_1 ----(many-to-one)---- tid_1
.... tid_2 ----(one-to-many)---- tid_2
tkey
tvalue
Is there a way to create a class, defined by Table 1
, with java.util.Map
, associating tkey
with tvalue
from Table 3
? I'm pretty new to Hibernate, and, before asking, I've tried to search and experiment, but got nothing. Any help will be appreciated.
P.S.
If this will not obstruct you, I'd prefer using .hbm.xml
style.
Upvotes: 2
Views: 635
Reputation: 242786
You can declare a map with tkey
as a key and an entity mapped to Table 3
as a value:
@Entity
public class Table1 {
@ManyToMany
@JoinTable(name = "Table2")
@MapKey(name = "key")
private Map<String, Table3> table3s;
...
}
@Entity
public class Table3 {
@Column(name = "tkey")
private String key;
@Column(name = "tvalue")
private String value;
...
}
Upvotes: 4