Hibernate配置流程
2024-08-26 21:52:13
操作数据库必须要设置数据库的连接属性:
- driver_class,url,username,password(hibernate.cfg.xml)
2. 编写对象跟表之间的映射关系(类名.hbm.xml)
为什么配置文件用xml?
①xml文件是可以通过规则文件提示的,
xml的规则文件有两种:dtd 和 schema 文件
②任何提供xml文件的框架,基本都提供规则文件
③大部分框架的XML规则文件都是在核心包里面的
④Eclipse可以通过配置XML的规则文件生成配置文件的。而且配置了规则文件,可以实现配置文件的标签提示
hibernate的配置流程图
第一步 、 在SRC目录下新建一个hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sms</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.formats_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<mapping resource="cn/gzsxt/hibernate/pojo/hbm/Student.hbm.xml"/> </session-factory>
</hibernate-configuration>
第二步 、
public class HibernateUtils { public static final SessionFactory ssf = getSessionFactory(); private static SessionFactory getSessionFactory() { //读取配置文件
Configuration config = new Configuration().configure();
//新建会话工厂
SessionFactory sessionFactory = config.buildSessionFactory(); return sessionFactory;
} public static Session getSession() {
Session session = ssf.openSession();
return session;
}
}
最新文章
- mysql的分区和分表
- 24. Swap Nodes in Pairs
- POJ 2151 Check the difficulty of problems
- If A wants to use B
- 原创:分享asp.net伪静态成目录形式iis如何设置
- 从AsyncTask中获取数据的问题
- 专为物联网开发的开源操作系统Contiki(转)
- 百度之星复赛Astar Round3
- android获取sdk更新
- css如此强大你知道吗
- Codeforces Round #257 (Div. 2) 题解
- 自己写的一个jQuery轮播插件
- [Direct2D1.1教程] Direct2D特效概览
- udp和tcp
- 通过自动回复机器人学Mybatis 笔记:接口式编程
- mysql 查询优化 ~ 优化基础补充
- 【C++】C++中typedef、auto与decltype的作用
- storage封装
- js 中格式化时间
- EF6+Sqlite连接字符串的动态设置
热门文章
- [转] Filezilla server设置指南及中文乱码、登录欢迎语问题解决
- RecyclerView 实现快速滚动 (转)
- 扩展和嵌入 Python 解释器 用 C 或 C++ 编写模块以使用新模块来扩展 Python 解释器的功能 定义新的函数\对象类型\方法。 将 Python 解释器嵌入到另一个应用程序中
- mybatis pagehelper 分页 失效
- Quartz Configuration Reference
- 写了一个具有future接口的rust测试代码
- darknet 的python接口使用
- expandablelistView 可展开的列表
- 【转】Python读取PDF文档,输出内容
- Spring cloud微服务安全实战-6-4权限控制改造