Hibernate的第一个程序

1、  创建一个java project

2、  导入jar包

 

3、 创建hibernate的配置文件:hibernate.cfg.xml

<hibernate-configuration>

      <session-factory>

           <!--

                 要链接数据库的用户名

            -->

           <property name="connection.username">root</property>

           <!--

                 要链接数据库的密码

            -->   

           <property name="connection.password">root</property>

           <!--

                 链接数据库的url

            -->

           <property name="connection.url">

                 jdbc:mysql://localhost:3306/itcastsh08_hibernate

           </property>

           <!--

                 方言

                      告诉hibernate用什么样的数据库

            -->

           <property name="dialect">

                 org.hibernate.dialect.MySQLDialect

           </property>

     <!--

                 validate  默认值

                      根据持久化类和映射文件检查表的结构

                 update

                 hibernate容器在启动的时候,会根据持久化类和映射文件检查表的结构

                 如果不存在,则创建,如果存在,则更新

                 create

                 每次启动hibernate容器,不管表是否存在,都会创建

                 create-drop

                 当启动hibernate容器时创建表,当hibernate容器销毁时,删除表

           -->

           <property name="hbm2ddl.auto">update</property>

引入映射文件

      <mapping resource="cn/itcast/sh08/hibernate/domain/Person.hbm.xml"/>

      </session-factory>

</hibernate-configuration>

Hibernate支持的所有的方言

4、 写代码,该代码完成了添加、修改、删除的操作

posted @ 2018-01-16 10:53  Love馨蕊  阅读(109)  评论(0编辑  收藏  举报