• Hibernate 环境配置和依赖添加(使用java web和普通javaSE工程)


    1.Hibernate依赖包的添加

    File---->Project Structure,按照如图所示操作,导入所依赖的jar包。

    2.生成hibernate.hbm.xml的配置文件

    (1)点击File,弹出的菜单中点击Project Structure;

    (2)点击左侧的Modules,再点击“+”号,再在弹出的菜单中选择Hibernate;

    (3)在这时,项目中多出了一个Hibernate,点击Hibernate,再点击“+”号,选择hibernate.hbm.xml;

    (4)弹出的窗口中选择Hibernate的版本,然后点击OK;

    (5)这时项目架子中多出了一个名为hibernate.hbm.xml的配置文件;

    3.配置数据库

    (1)点击左下角按钮,使窗口样式如图所示;

     (2)选择数据库;

    (3)配置数据库后测试连接是否成功,若成功后点击确定;

    4.生成Hibernate的实体类以及配置文件

    (1)点击窗口中的Persistence;

    (2)选择数据源,配置实体类包,选择要生成的实体类(其中日期类型的只能手动修改为java.util.Date),然后点击OK

    (2)点击ok,后会生成如下内容

    hibernate.cfg.xml文件配置如下:

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
    
        <property name="connection.url">jdbc:mysql://localhost:3306/storereviews?serverTimezone=UTC&amp;useSSL=false</property>
        <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
        <property name="connection.username">root</property>
        <property name="connection.password">plj888888</property>
    
        <!-- DB schema will be updated if needed -->
        <!-- <property name="hbm2ddl.auto">update</property> -->
    
    
        <mapping resource="ProductClass/Huaweip20Taobao.hbm.xml"/>
        <mapping resource="ProductClass/Iphonexrtaobao.hbm.xml"/>
        <mapping resource="ProductClass/Totalcommentxiaomi8.hbm.xml"/>
        <mapping resource="ProductClass/Xiaomi8Taobao.hbm.xml"/>
        <mapping resource="ProductClass/Fenciresult.hbm.xml"/>
        <mapping resource="ProductClass/Jufaanalyze.hbm.xml"/>
        <mapping resource="ProductClass/Qinggananalyze.hbm.xml"/>
        <mapping resource="ProductClass/Productfeature.hbm.xml"/>
        <mapping resource="ProductClass/Opinionword.hbm.xml"/>
        <mapping resource="ProductClass/Featurewordtree.hbm.xml"/>
        <mapping resource="ProductClass/Featureandfreq.hbm.xml"/>
        <mapping resource="ProductClass/Advword.hbm.xml"/>
        <mapping resource="ProductClass/Objectiveword.hbm.xml"/>
        <mapping resource="ProductClass/Xiaomi8Taobaonew.hbm.xml"/>
        <mapping resource="ProductClass/Problemfreq.hbm.xml"/>
        <mapping resource="ProductClass/Huaweip20Taobaonew.hbm.xml"/>
        <mapping resource="ProductClass/Iphonexrtaobaonew.hbm.xml"/>
        <mapping resource="ProductClass/WordsParagraphsEntity.hbm.xml"/>
        <mapping class="ProductClass.WordsParagraphsEntity"/>
    
    
      </session-factory>
    </hibernate-configuration>
  • 相关阅读:
    Postman的使用和测试
    Django报错 django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
    MySQL 修改字段类型或长度
    mysql导入导出sql文件
    Django 无法同步数据库model相应字段问题
    Django objects.all()、objects.get()与objects.filter()之间的区别介绍
    inconsistent use of tabs and spaces in indentation
    JavaScript 计时器
    JavaScript--编程题
    JavaScript--Array 数组对象
  • 原文地址:https://www.cnblogs.com/luckyplj/p/10655739.html
Copyright © 2020-2023  润新知