來自:https://blog.csdn.net/chenyunqiang/article/details/81026823
1、構建項目並添加項目結構配置以及配置初始參數
1.1、如圖將基本的架子搭建好

1.2、點擊File,彈出的菜單中點擊Project Structure;
1.3、點擊左側的Modules,再點擊“+”號,再在彈出的菜單中選擇Hibernate;

1.4、在這時,項目中多出了一個Hibernate,點擊Hibernate,再點擊“+”號,選擇hibernate.hbm.xml;

1.5、彈出的窗口中選擇Hibernate的版本,然后點擊OK;

1.6、點擊OK后在原來1.4步驟的窗口中的Apply按妞應用到項目;
1.7、這時項目架子中多出了一個名為hibernate.hbm.xml的配置文件;

1.8、在hibernate.hbm.xml中配置如下配置;
-
-
-
-
-
<hibernate-configuration>
-
<session-factory>
-
<!–數據庫連接url配置–>
-
<property name=“connection.url”>jdbc:mysql://localhost:3306/SSHBlog?useUnicode=true&characterEncoding=utf8&useSSL=true&zeroDateTimeBehavior=convertToNull</property>
-
<!–數據庫驅動配置–>
-
<property name=“connection.driver_class”>com.mysql.jdbc.Driver</property>
-
<!–數據庫用戶名配置–>
-
<property name=“connection.username”>root</property>
-
<!–數據庫密碼配置–>
-
<property name=“connection.password”></property>
-
-
<!– DB schema will be updated if needed –>
-
<!– <property name=”hbm2ddl.auto”>update</property> –>
-
</session-factory>
-
</hibernate-configuration>
- 1
1.9、第一步配置完畢。
2、配置數據庫
2.1、點擊左下角按鈕,使窗口樣式如圖所示;

2.2、選擇數據庫;

2.4、配置數據庫后測試連接是否成功,若成功后點擊確定;

2.5、數據庫如下;


3、生成Hibernate的實體類以及配置文件
3.1、點擊窗口中的Persistence;

3.2、在Persistence中右鍵項目,然后點擊Generate Persistence Mapping,選擇By Database Schema;

3.3、選擇數據源,配置實體類包,選擇要生成的實體類(其中日期類型的只能手動修改為java.util.Date),然后點擊OK;


3.4、等待一段時間之后,發現項目中的實體類以及配置文件已經自動生成。
