zoukankan      html  css  js  c++  java
  • Hibernate二 配置

    1、hibernate.cfg.xml文件,配置数据库连接信息和实体的映射文件信息

    <hibernate-configuration>
        <session-factory>
            <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate_first</property>
            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.connection.password">bjsxt</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>


            <property name="hibernate.show_sql">true</property>


            <mapping resource="com/bjsxt/hibernate/User.hbm.xml"/>  //这里是实体的映射文件
        </session-factory>
    </hibernate-configuration>

    2、具体对象的映射信息

    <hibernate-mapping>
        <class name="com.bjsxt.hibernate.User">
            <id name="id">
                <generator class="uuid"/>
            </id>
            <property name="name"/>
            <property name="password"/>
            <property name="createTime"/>
            <property name="expireTime"/>
        </class>
    </hibernate-mapping>

     

    开发流程

    1、新建java项目

    2、创建User Library,加入如下jar
        * HIBERNATE_HOME/hibernate3.jar
        * HIBERNATE_HOME/lib/*.jar
        * MySql jdbc驱动
    3、创建hibernate配置文件hibernate.cfg.xml,为了便于调试最好加入log4j配置文件

    4、定义实体类

    5、定义User类的映射文件User.hbm.xml

    6、将User.hbml.xml文件加入到hibernate.cfg.xml文件中

    7、编写hbm2ddl工具类,将实体类生成数据库表

    8、开发客户端
    为了方便跟踪sql执行,在hibernate.cfg.xml文件中加入<property name="hibernate.show_sql">true</property>

  • 相关阅读:
    python 环境常用指令(updating...)
    English Voice of <<Take Me To Your Heart>>
    English trip V2-B 1 What's on the Menu? 菜单上有什么? Teacher:Tom
    VM-ESXI 相关常用命令(Updateing)
    English trip EM2- LP 5B Eating Right 正确的饮食 Teacher:Gabi
    (转)Linux中的screen命令使用
    Centos7 密码遗忘-单用户模式
    数据集
    SVD 实现
    网易音乐推荐原理及算法
  • 原文地址:https://www.cnblogs.com/guaniu/p/2325825.html
Copyright © 2011-2022 走看看