zoukankan      html  css  js  c++  java
  • 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、 写代码,该代码完成了添加、修改、删除的操作

    Love馨蕊
  • 相关阅读:
    【MyBatis】STDOUT_LOGGING和log4j日志
    【MyBatis】resultType与类的字段不同解决办法
    【MyBatis】SqlSession相关的生命周期及作用域
    【MyBatis】XML配置的官网说明
    【Junit】程序员都应会的白盒测试
    【MyBatis】增删改查语句入门
    【MyBatis】我的mybatis第一个程序
    【网络】HTTP知识点(1)
    InitializeComponent报错(提示不存在)
    leetcode 860柠檬水找零问题
  • 原文地址:https://www.cnblogs.com/yuan211/p/8295420.html
Copyright © 2011-2022 走看看