Hibernate的配置文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qwl755/article/details/84338068

对Ehibernate的核心配置文件可以有两种:

  1. hibernate.cfg.xml
  2. hibernate.properties
  • 通过properties这种方式,不能配置<mapping>映射
  • 编码实现 Configuration config-new configuration ().addResource (xxx.hbm.xml) ;

核心配置文件hibernate.cfg.xml文件常用属性

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">qaz123</property>


<property name="hibernate.show_sql">true</property><!-- 显示sql语句 -->
<property name="hibernate.format_sql">true</property><!-- 格式化sql语句 -->

*DDL主要建表语句,和表结构更新语句

<property name="hibernate.hbm2ddl.auto ">create/create-drop/update/validate</property>

  • screate表示启动的时候先drop,再ceate (测试人员准备标准测试数据)
  • create-drop:也表示创建,只不过再系统关闭前执行一下drop (测试程序是否正确)
  • update:这个操作启动的时候会去检查表与类是否一致,如果不一致会做更新(建表,更新表结构【只能加】)
  • validate:启动时验证现有表与你配置的hibernate是否一致,如果不一致就抛出是常,并不做更新

**在产品开发电update和validate使用较多

<property name="hibernate.connection.autacommit">true</property>

设置事务自动提交.(有问题******.)

问题原因:如果设置成自动事务,执行后,通过session.flush ()就可以

猜你喜欢

转载自blog.csdn.net/qwl755/article/details/84338068