Hibernate mapping - map through table
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 Hibern开发者_如何转开发ate, 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.
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;
...
}
精彩评论