4.集合映射:测试
2016-06-23 10:59
357 查看
package com.bjpowernode.hibernate; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import org.hibernate.Session; public class CollectionMappingTest extends TestCase { @SuppressWarnings("unchecked") public void testSave1() { Session session = null; try { session = HibernateUtils.getSession(); session.beginTransaction(); CollectionMapping c = new CollectionMapping(); c.setName("XXX"); // Set setValues = new HashSet(); // setValues.add("a"); // setValues.add("b"); // c.setSetValues(setValues); c.getSetValues().add("a"); c.getSetValues().add("b"); c.getListValues().add("c"); c.getListValues().add("d"); String[] arrayValues = new String[]{"e", "f"}; c.setArrayValues(arrayValues); Map mapValues = new HashMap(); mapValues.put("k1", "v1"); mapValues.put("k2", "v2"); c.setMapValues(mapValues); session.save(c); session.getTransaction().commit(); }catch(Exception e) { e.printStackTrace(); session.getTransaction().rollback(); }finally { HibernateUtils.closeSession(session); } } @SuppressWarnings("unchecked") public void testLoad1() { Session session = null; try { session = HibernateUtils.getSession(); session.beginTransaction(); CollectionMapping c = (CollectionMapping)session.get(CollectionMapping.class, 1); System.out.println("name=" + c.getName()); System.out.println("setValue=" + c.getSetValues()); System.out.println("listValue=" + c.getListValues()); System.out.println("arrayValue=" + c.getArrayValues()); System.out.println("mapValue=" + c.getMapValues()); session.getTransaction().commit(); }catch(Exception e) { e.printStackTrace(); session.getTransaction().rollback(); }finally { HibernateUtils.closeSession(session); } } }
相关文章推荐
- 3.集合映射:hibernate.cfg.xml
- python print函数
- 2.集合映射:工具类
- 金额数字字符串整数位每三位加个逗号
- 1.集合映射:Object,hbm
- android adb push 与 adb install的比较(两种安装APK的方法)
- 产品设计文档及工作流程
- 第二冲刺阶段个人进度05
- 开发中遇到的angularJs的小问题
- centos 修改时区及NTP时间同步
- WebService异常Unexpected wrapper element ... found. Expected ...
- 使用svn diff的-r参数 svn merge的用法
- 一点一滴分析LinkIt™ Smart 7688 按钮操作
- 实习日记4_2016.06.23
- 深入浅出RxJava(二:操作符)
- Android退出应用最优雅的方式
- SQL索引一步到位
- 001.Two Sum
- redis for hash操作简单总结
- [干货汇总]LSA及SVD介绍