hibernate 主配置文件
来源:互联网 发布:淘宝下载windows10 编辑:程序博客网 时间:2024/06/10 01:26
Hibernate.cfg.xml
主配置文件中主要配置:数据库连接信息、其他参数、映射信息!
常用配置查看源码:
hibernate-distribution-3.6.0.Final\project\etc\hibernate.properties
<!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration><!-- 通常,一个session-factory节点代表一个数据库 --><session-factory> <property name="hibernate.connection.characterEncoding">utf-8</property><!-- 编码问题 --><!-- 1. 数据库连接配置 --><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.url">jdbc:mysql:///struts</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">123456</property><!-- 数据库方法配置, hibernate在运行的时候,会根据不同的方言生成符合当前数据库语法的sql --><property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property><!-- 2. 其他相关配置 --><!-- 2.1 显示hibernate在运行时候执行的sql语句 --><property name="hibernate.show_sql">true</property><!-- 2.2 格式化sql --><property name="hibernate.format_sql">true</property><!-- 2.3 自动建表 --><property name="hibernate.hbm2ddl.auto">update</property><!-- 3. 加载所有映射 --><mapping resource="cn/hib/test/Employee.hbm.xml"/></session-factory></hibernate-configuration>
数据库连接参数配置
例如:
## MySQL
#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialectorg.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialectorg.hibernate.dialect.MySQLMyISAMDialect
#hibernate.connection.driver_classcom.mysql.jdbc.Driver
#hibernate.connection.urljdbc:mysql:///test
#hibernate.connection.username gavin
#hibernate.connection.password
自动建表
Hibernate.properties
#hibernate.hbm2ddl.auto create-drop 每次在创建sessionFactory时候执行创建表;
当调用sesisonFactory的close方法的时候,删除表!
#hibernate.hbm2ddl.auto create 每次都重新建表; 如果表已经存在就先删除再创建
#hibernate.hbm2ddl.auto update 如果表不存在就创建; 表存在就不创建;
#hibernate.hbm2ddl.auto validate (生成环境时候) 执行验证: 当映射文件的内容与数据库表结构不一样的时候就报错!一般希望在应用程序启动时就创建数据库表,而不是在hibernate调用时创建,见下代码:
publicclass App_ddl { // 自动建表 @Test publicvoid testCreate() throws Exception { // 创建配置管理类对象 Configuration config = new Configuration(); // 加载主配置文件 config.configure(); // 创建工具类对象 SchemaExport export = new SchemaExport(config); // 建表 // 第一个参数:是否在控制台打印建表语句 // 第二个参数:是否执行脚本 export.create(true, true); }}
- Hibernate配置文件之主配置文件
- Hibernate主配置文件属性
- Hibernate-主配置文件
- Hibernate主配置文件
- Hibernate:主配置文件
- Hibernate主配置文件
- hibernate主配置文件
- hibernate 主配置文件
- Hibernate主配置文件
- Hibernate主配置文件hibernate.cfg.cml详解
- Hibernate主配置文件(hibernate.cfg.xml)
- Hibernate的主配置文件hibernate.cfg.xml
- Hibernate的主配置文件hibernate.cfg.xml
- Hibernate的主配置文件hibernate.cfg.xml
- Hibernate的主配置文件hibernate.cfg.xml
- Hibernate的主配置文件hibernate.cfg.xml
- Hibernate的主配置文件hibernate.cfg.xml
- Hibernate主配置文件(hibernate.cfg.xml)
- .net项目技术选型总结
- zuul的简单笔记
- java.nio.charset.MalformedInputException: Input length = 1
- SQL的having,distinct,exists用法介绍
- 带logo的二维码生成
- hibernate 主配置文件
- 适配器模式
- 解决chrome获取图片宽度和高度为0问题
- vnc使用过程中的问题
- iOS Mac版 终端安装weex环境以及运行效果
- Java多线程--并发中集合的使用之LinkedBlockingDeque
- Android调用外部ContentProvider失败
- jquery easyui自动补全
- AngualrJs ui-router动态设置ng-class