當前位置:首頁 » 操作系統 » hibernate3源碼

hibernate3源碼

發布時間: 2023-07-17 10:45:05

① 如何學習hibernate源碼

學習 Hibernate 源碼一
1. 下載 hibernate 源碼,並構建起 eclipse 項目
( 1 ) hibernate 的源代碼採用 git 管理,安裝 git 客戶端以後,通過點擊 github.com/hibernate/hibernate-orm 頁面右側的「 Clone in Desktop 」可啟動客戶端將代碼 clone 到本地。當然也可以直接使用
git clone git://github.com/hibernate/hibernate-orm.git
命令下載代碼。
下載完畢後,打開根目錄下的 readme 文件,可以看到詳細的把源代碼構建為不同 IDE 項目的說明;以及其他的一些信息。
對應文檔的網站鏈接:
community.jboss.org/wiki/BuildingHibernateORM4x5x
構建 IDE 部分:
Eclipse
To create the Eclipse project files you can run
After changes to the dependencies you need to clean the project files and recreate them:
./gradlew cleanEclipse eclipse
See also Contributing to Hibernate using Eclipse
Idea
To create the Idea project files you can run
./gradlew idea
After changes to the dependencies you need to clean the project files and recreate them:
./gradlew cleanIdea idea
此處的 gradle 是 hibernate 所使用的自動構建工具,官網地址為行基:
.gradle.org/
下載地址為: .gradle.org/downloads ,選擇一個版本進行下載
此處是 Hibernate 團隊闡述其從 Maven 遷移到 Gradle 的原因: community.jboss.org/wiki/GradleWhy
褲腔至於 grable ,有時間會深入學習一下,感興趣的同學可以看看這位博主的博客:
.blogjava.net/wldandan/archive/2012/06/26/381532.html
言歸正傳,下載 grable 後,解壓,我將胡帶衫其解壓到了 C 盤根目錄,解壓完畢的 grable 所在目錄為: C:\gradle-1.7 ,將其子目錄 C:\gradle-1.7\bin 目錄加入系統的 Path 變數
編譯代碼為 eclipse 項目:
( 1 )進入 hibernate 源碼的根目錄:
cd C:\Users\Administrator\Documents\GitHub\hibernate-orm
( 2 )執行 gradlew.bat eclipse
接著會自動下載項目所需要的依賴項,具體輸出如下:
C:\Users\Administrator\Documents\GitHub\hibernate-orm >gradlew.bat eclipse
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheled to be removed in Gradle 2.0. Please read gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on
Deprecated dynamic property: "exportPackageVersion" on "project ':documentation'", value: "4.3.0".
Deprecated dynamic property "exportPackageVersion" created in multiple locations.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\Administrator\Documents\GitHub\hibernate-orm\build.gradle' line: 85
* What went wrong:
A problem occurred evaluating root project 'hibernate-orm'.
> org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager : Unsupported major.minor version 51.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
此時我去查看我的環境變數, JAVA_HOME 指向的是 64 位的 JDK6 ,將其指向 32 位 JDK7 後再次執行
gradlew.bat eclipse
發現此時 gradlew 又去下載了其他的依賴包,查看 hibernate-rom 目錄下的 libraries.gradle 文件,可以看到 hibernate 的依賴包。
重新編譯過程中還是報錯了,具體錯誤:
:hibernate-core:compileJava
警告 : [options] 未與 -source 1.6 一起設置引導類路徑
C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\Loader.java:38: 錯誤 : 編碼 GBK 的不可映射字元
* @author L 錕絪 zl 錕 ?Benke
^
C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\ResultCheckStyle.java:29: 錯誤 : 編碼 GBK 的不可映射字元
* @author L 錕絪 zl 錕 ?Benke
^
C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLDelete.java:37: 錯誤 : 編碼 GBK 的不可映射字元
* @author L 錕絪 zl 錕 ?Benke
^
C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLDeleteAll.java:37: 錯誤 : 編碼 GBK 的不可映射字元
* @author L 錕絪 zl 錕 ?Benke
^
C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLInsert.java:37: 錯誤 : 編碼 GBK 的不可映射字元
* @author L 錕絪 zl 錕 ?Benke
^
C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLUpdate.java:37: 錯誤 : 編碼 GBK 的不可映射字元
* @author L 錕絪 zl 錕 ?Benke
^
注 : 某些輸入文件使用或覆蓋了已過時的 API 。
注 : 有關詳細信息 , 請使用 -Xlint:deprecation 重新編譯。
注 : 某些輸入文件使用了未經檢查或不安全的操作。
注 : 有關詳細信息 , 請使用 -Xlint:unchecked 重新編譯。
1 個警告
google 了一下,貌似是區域語言設置的問題,需要修改為「英語(英國)」,但編譯並沒用中斷,接著編譯。我將控制面板中的區域語言設置修改後,繼續觀察,看其是否還會報同樣的錯誤。
最終還是失敗了:
:hibernate-entitymanager:compileJava
警告 : [options] 未與 -source 1.6 一起設置引導類路徑
C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-entitymanager\src\main\java\org\hibernate\jpa\AvailableSettings.java:290: 錯誤 : 編碼 GBK 的不可映射字元
* contains 鈥淐 REATE SCHEMA 鈥 ?commands. If this property is not supplied (or is explicitly {@code false}), the
^
注 : 某些輸入文件使用或覆蓋了已過時的 API 。
注 : 有關詳細信息 , 請使用 -Xlint:deprecation 重新編譯。
注 : 某些輸入文件使用了未經檢查或不安全的操作。
注 : 有關詳細信息 , 請使用 -Xlint:unchecked 重新編譯。

② 怎麼查看hibernate源碼

方法/步驟

進入官網:hibernate.org

2、在跳轉之後的頁面中點擊「Downloads」

3、至此jar包的下載就完成
4、下載源碼包,點擊「Source code」,之後會跳轉到github網站上 :

5、點擊右下角的「Download ZIP」至此,源碼包也下載完畢

③ 如何學習hibernate源碼

我來分享一下查看源碼的方法:

查看源碼的首要任務是要有一款上手的工具,這里用的是 IDEA。IDEA 的功能比較強大,包括 查看類結構圖,debug。這兩個是查看源碼的關鍵功能。

查看源碼可以靜態查看和動態查看,靜態查看的方法是查看類圖,還有 ALT + f7 查看方法在哪裡被調用或者類在哪裡被調用。在看 spring 源碼的時候就是用這種方法,不過這種方法對閱讀者的要求比較高,包括要了解這個方法的執行,設計模式的理解,以及框架是如何配置這個類的。第二種方法是 debug。debug 方法是後來才發現的一個重要的 查看源碼的方法,要點是掌握執行棧,就能掌握整個執行流程。比如這個是在debug hibernate 源碼的時候的截圖,可以看到這個執行棧非常深,從 spring-data-jpa 到 hibernate 中間經過好幾層的代理,主要完成一些適配,事務,攔截器等等操作,然後再到 hibernate 核心代碼,最後就是 jdbc 的 statement。方法棧中的每一個方法都是可以查看的,裡面的變數有時候是代理了好幾層,所以要 F7 進去才能看到真正的執行類。

上面是簡單的簡述 mybatis 的 cache 機制的源碼,真正想讓讀者明白的是,debug 如何查看源碼,查看源碼需要抓住一個主題,不然在閱讀龐大的框架的時候會找不著北。

所以,閱讀源碼需要掌握工具使用,debug, 查看類圖,查看方法在哪裡調用,軟知識是要掌握設計模式,對框架的概念有了解。

熱點內容
怎麼搭建linux伺服器ftp 發布:2025-03-16 07:07:38 瀏覽:987
晶元存儲原理 發布:2025-03-16 06:58:21 瀏覽:284
c語言中的整型 發布:2025-03-16 06:40:48 瀏覽:184
分部資料庫伺服器的IP地址有效 發布:2025-03-16 06:33:40 瀏覽:192
安卓項目如何配置tomacat 發布:2025-03-16 06:31:13 瀏覽:431
寫腳本測試 發布:2025-03-16 06:20:07 瀏覽:780
多個撥號寬頻如何配置 發布:2025-03-16 05:51:35 瀏覽:688
管理員c語言 發布:2025-03-16 05:40:17 瀏覽:342
安卓軟體上的圖案如何更改 發布:2025-03-16 05:35:57 瀏覽:748
2010編譯c中文亂碼 發布:2025-03-16 05:33:40 瀏覽:550