Hibernate集合映射Set和Map

Set和Map基本和List一样

先看Set   只需要将List改为private Set emails = new HashSet(0);

然后修改User.hbm.xml文件就可以了

<set name="emails" table="emails">
			<key column="userid" foreign-key="id" />
			<element type="string" column="email" />
		</set>

再看Map  同样的  private Map emails = new HashMap();

<map name="emails" table="email">
			<key column="userid" foreign-key="id" />
			<map-key column="sb" type="string" />
			<element column="email" type="string" />
		</map>

相关推荐