首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

[转]hibernate 集合类(Collections)映射(四)- 地图

2012-09-04 
[转]hibernate 集合类(Collections)映射(四)- map四、Map集合映射?Map集合属性不仅需要映射属性value,还需

[转]hibernate 集合类(Collections)映射(四)- map

四、Map集合映射

?

Map集合属性不仅需要映射属性value,还需要映射属性key。这里假设Employee的name属性是唯一的,如下修改Employee.hbm.xml配置文件中的name属性,设置unique='true':

?

Java代码

<property name="name"?

<property name="name"?

Java代码

public?

?????????//setter和getter方法??

?

}?

?

public?

?????????//setter和getter方法

?

}?

Xml代码

<?xml version="1.0"?>?

<!DOCTYPE hibernate-mapping PUBLIC???

??????<hibernate-mapping?????????????????????????????????????????????????????????????????????????????????????</hibernate-mapping>?

?

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

??????<hibernate-mapping?????????????????????????????????????????????????????????????????????</hibernate-mapping>?

Java代码

//List<Employee> list= new ArrayList<Employee>();??

//?????????//??????????????????????????????????????????????????????

//List<Employee> list= new ArrayList<Employee>();

//????????//?????????????????????????????????????????????????

emps:{employee1 name1?

数据库表中记录如下所示(未发生变化):

?

mysql> select * from department;

+----+-----------------+

| id | name???????????+----+-----------------+

|?+----+-----------------+

1 row in set (0.00 sec)

?

mysql> select * from employee;

+----+-----------------+-----------+

| id | name???????????+----+-----------------+-----------+

|?|?+----+-----------------+-----------+

2 rows in set (0.00 sec)

热点排行