Hibernate Annotaion映射Map
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import javax.persistence.Column;
6 import javax.persistence.Entity;
7 import javax.persistence.GeneratedValue;
8 import javax.persistence.Id;
9 import javax.persistence.JoinColumn;
10 import javax.persistence.JoinTable;
11 @Entity
12 public class Content {
13 @Id
14 @GeneratedValue
15 private int id;
16 @org.hibernate.annotations.CollectionOfElements
17 @JoinTable(name = "content_attr", joinColumns = @JoinColumn(name = "content_id"))
18 @org.hibernate.annotations.MapKey(columns = @Column(name = "attr_value"))
19 private Map<String, String> attr = new HashMap<String, String>();
20
21 public int getId() {
22 return id;
23 }
24
25 public void setId(int id) {
26 this.id = id;
27 }
28
29 public Map<String, String> getAttr() {
30 return attr;
31 }
32
33 public void setAttr(Map<String, String> attr) {
34 this.attr = attr;
35 }
36
37 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。