<?xml version="1.0" encoding="utf-8" ?>
<!--
  ~ Hibernate, Relational Persistence for Idiomatic Java
  ~
  ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
  ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
  -->
<!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>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:mysql:///test</property>
      <property name="connection.username">root</property>
      <property name="connection.password">123456</property>
      <!--方言-->
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <!--数据库生成方式    create 每次执行前删除表数据,重新创建然后创建该表,这是导致数据库表数据丢失的一个原因;
      c0reate-drop 每次执行前删除表数据,重新创建然后创建该表,sessionFactory关闭时将删除该数据表;
      validate 每次加载hibernate时,都将验证数据表结构,只会和数据库中的表作比较,不会创建新表,不一致就会抛出异常,但是会插入新值;
      update  最常用的属性,第一次加载hiberbnate时根据model类会自动建立起表的结构(前提是先建立好数据库),以后加载hibernate时根据model类自动更新表结构,即使
      表结构改变了,但表中原来的行仍然存在,不会删除表中原来的行,要注意的是,在部署到服务器后,表结构是不会被马上建立起来的,是要等应用第一次运行起来后;
      -->
      <property name="hibernate.hbm2ddl.auto">update</property>
      <!--映射-->
      <mapping resource="com/test/bean/Test.hbm.xml"/>
   </session-factory>
</hibernate-configuration>

 

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐