Hibernate.cfg.xml,Session常用模板
来源:互联网 发布:橙树网络 编辑:程序博客网 时间:2024/06/05 22:49
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="connection.dirver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/dbtest</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<!--指定连接的语言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/bean/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
2、
在HibernateUtil.java 类中编写SessionFactory 的获得,以及Session 实例的打开和关闭代码,如下所示:// HibernateUtil.javapublic class HibernateUtil {private static final SessionFactory sessionFactory;//取得sessionFactorystatic {try {sessionFactory = new Configuration().configure().buildSessionFactory();} catch (HibernateException ex) {throw new RuntimeException("Exception building SessionFactory: "+ ex.getMessage(), ex);}}//开启sessionpublic static Session currentSession() {Session s = sessionFactory.openSession();return s;}//关闭sessionpublic static void closeSession(Session s){s.close();}}
- Hibernate.cfg.xml,Session常用模板
- hibernate.cfg.xml模板
- hibernate.cfg.xml模板
- Hibernate配置文件模板(.cfg.xml)
- hibernate.cfg.xml 配置模板
- hibernate.cfg.xml 配置模板
- Hibernate配置文件模板(.cfg.xml)
- hibernate.cfg.xml 常用配置
- hibernate配置文件:hibernate.cfg.xml常用属性
- Hibernate.cfg.xml配置文件模板及解析
- Hibernate.cfg.xml配置文件模板及解析
- 1002--hibernate.cfg.xml的常用属性
- hibernate.cfg.xml的常用配置
- hibernate.cfg.xml文件的常用属性
- hibernate.cfg.xml的常用属性
- Hibernate.cfg.xml常用配置总结
- hibernate.cfg.xml的常用的配置
- hibernate配置文件hibernate.cfg.xml安全线程的session配置
- 0x800700E1: 无法成功完成操作,因为文件包含病毒 解决方法
- 如何在旧型号EVB中使用新版本固件?
- Linux系统调用列表(收藏)
- H264码流的NAL起始字节分析
- shell编程之给变量赋值的五种方法
- Hibernate.cfg.xml,Session常用模板
- OpenStack学习笔记————什么是云计算
- 无法在线获取ADT插件解决方法
- WebView的缩放功能
- 经典SQL语句大全之基础 .
- 网络编程之即时通信程序(聊天室)------(一)通信流程简介及通信协议定制
- frame bounds contentOffset contentInset
- shell(查当前cpu数,然后编译内核)
- 如何 旋转Windows Mobile 2003的屏幕