private Long id; private String username; private String password; private Map<String,String> phone = new HashMap<String,String>() ; 一个用户有多个电话,需要以map形式存取 <map name="phone" table="userphone" order-by="phone_number"> <key column="userid" foreign-key="id"></key> <map-key type="java.lang.String" column="phone_type"></map-key> <element type="java.lang.String" column="phone_number"></element> </map> 在配置文件里面map需要配置key和value 对应hibernate里面的 <map-key>和<element> 测试类: package com.test; import java.util.HashMap; import java.util.Map; import java.util.Set; import org.hibernate.Session; import com.pojo.User; import com.util.HibernateManager; public class HibernateTestMap { /** * beckham Dec 12, 2009 9:21:01 PM */ private static Session session = null; public static void main(String[] args) { HibernateTestMap.load(); } public static void add() { session = HibernateManager.openSession(); User u = new User(); u.setUsername("wuqin"); u.setPassword("222222"); Map<String,String> map = new HashMap<String,String>(); map.put("home", "13000000000") ; map.put("company", "010888888") ; map.put("linshi", "0210000000") ; u.setPhone(map) ; try { session.save(u); HibernateManager.closeSession(); } catch (Exception e) { HibernateManager.rollbackTransaction(); } } @SuppressWarnings("unchecked") public static void load() { session = HibernateManager.openSession(); try { User user = (User) session.get(User.class, new Long(1)); System.out.println("用户名:" + user.getUsername()); System.out.println("密码:" + user.getPassword()); Map<String,String> map = user.getPhone() ; Set<String> set = map.keySet() ; for (String phone : set) { System.out.println(phone+"---------"+map.get(phone)); } HibernateManager.closeSession(); } catch (Exception e) { e.printStackTrace(); HibernateManager.rollbackTransaction(); } } }