首页 > 代码库 > Hibernate Annotaion映射Map
Hibernate Annotaion映射Map
1 package com.jl.module.test.bean;
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 }
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 }
Hibernate Annotaion映射Map
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。