Hibernate(一)Hibernate初识
来源:互联网 发布:mqttws31.js tcp 连接 编辑:程序博客网 时间:2024/05/21 10:55
junit单元测试
Hibernate 4.3.11+junit4.8
public class StudentsTest { private SessionFactory sessionFactory; private Session session; private Transaction transaction; @SuppressWarnings("deprecation") @Before public void init(){ //创建配置对象 Configuration config = new Configuration().configure(); //创建服务注册对象 ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); //创建会话工厂对象 sessionFactory = config.buildSessionFactory(serviceRegistry); //会话对象 session = sessionFactory.openSession(); //开启事务 transaction = session.beginTransaction(); } @Test public void testSaveStudents(){ //生成学生对象 Students s = new Students(1,"张三","男","ss",new Date()); //session.save(s); } @After public void destory(){ transaction.commit();//提交事务 session.close(); sessionFactory.close(); }}
Hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">123456</property> <property name="hibernate.connection.url">jdbc:mysql:///hibernate?useUnicode=true&characterEncoding=UTF-8</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">create</property> <!-- 配置hbm映射文件 --> <mapping resource="Students.hbm.xml"/> </session-factory></hibernate-configuration>
阅读全文
0 0
- Hibernate(一)Hibernate初识
- 一、初识Hibernate
- Hibernate学习笔记(一)----初识Hibernate
- hibernate 学习笔记一(初识hibernate)
- Hibernate 学习(一)初识Hibernate
- 初识Hibernate
- 初识hibernate
- 初识Hibernate
- hibernate初识
- 初识Hibernate
- Hibernate初识
- 初识hibernate
- 初识Hibernate
- Hibernate初识
- hibernate初识
- hibernate初识
- 初识Hibernate
- Hibernate----初识
- VS2015动态库静态加载时指定动态库位置的方法
- 【PostgreSQL-9.6.3】函数(2)--字符型函数
- Android实现双击退出应用
- 怒赞!FACEBOOK内部高效工作PPT指南
- java AES加密解密实例
- Hibernate(一)Hibernate初识
- NBA投票系统(1):系统介绍
- linux内核协议栈之IPV6与路由
- html中linewidth示例
- 指数型组织:打造独角兽公司的11个最强属性
- j2ee-规范-jdbc四种驱动
- html中linecap示例
- html中lineJoin示例
- Spring的配置文件