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>
复制代码

 

posted @   雨后观山色  阅读(541)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示