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馨蕊
  • 相关阅读:
    BZOJ3105 新Nim游戏 【拟阵】
    Codeforces1037G A Game on Strings 【SG函数】【区间DP】
    @RequestBody和@RequestParam
    Swagger学习
    单点登录SSO
    工作流学习
    Lombok
    PageHelper分页插件
    mybatis逆向工程介绍
    跨域请求的解决方案
  • 原文地址:https://www.cnblogs.com/yuan211/p/8295420.html
Copyright © 2011-2022 走看看