Hibernate 创建session的步骤
来源:互联网 发布:yum 强制卸载命令 编辑:程序博客网 时间:2024/04/30 03:56
//获取配置对象Configuration configuration = new Configuration().configure();//获取注册服务对象 ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();//获取session工厂对象SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);//创建会话对象,需要手动关闭session//Session session = sessionFactory.openSession();//无需手动关闭session,这种会话对象在事物提交或者回滚后会自动关闭Session session = sessionFactory.getCurrentSession();//创建事物Transaction transaction = session.getTransaction();//开启事物transaction.begin();//先生成被控类对象,注意pid是18位IdCard card = new IdCard("123456789012345678","张无忌");//创建一个学生Student student = new Student(card,"男",new Date(),"计算机");session.save(card);session.save(student);//使用openSession();创建session的话,最后需要手动关闭session,否则会一直持有connection的引用//session.close();//提交事物transaction.commit();
阅读全文
0 0
- Hibernate 创建session的步骤
- 创建Hibernate项目的步骤
- hibernate结束session的四个独立步骤
- 创建Hibernate的例子的步骤
- 细说创建Hibernate程序的四大步骤
- hibernate之session实例的创建
- hibernate之session实例的创建
- 创建Hibernate获取Session的工具类
- Hibernate创建sessionFactory,session和关闭session的工具类
- hibernate创建session工厂
- HIbernate 创建Session 对象
- hibernate创建Session()值
- Hibernate入门(四)之hibernate中session的创建方式
- HibernateSessionFactory类中Session对象的创建步骤
- hibernate的创建session的两种方法
- Hibernate中SessionFactory的创建和Session的获取
- 创建简单hibernate项目步骤
- Hibernate中Session对象创建的几种方式
- Linux 串口通信接口
- 86. Partition List
- Netty源码阅读(一) ServerBootstrap启动
- 学习head first 设计模式之观察者模式
- socket属性设置与初始化操作
- Hibernate 创建session的步骤
- 进入阿里必备知识-第二步-HSF学习
- 最简单的视频网站(JavaEE+FFmpeg)
- Python之Numpy库
- 空指针的那些事
- jsp开发项目中的问题解决
- vs+opencv 的解决方案加载失败的问题
- 代码实现cpu的检测和内存使用情况
- java并发编程的艺术【三】-【二】重排序与顺序一致性