1. 程式人生 > >JavaEE專案(結合maven)出現的各種錯誤總結

JavaEE專案(結合maven)出現的各種錯誤總結

專案的基本報錯都是

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Servlet execution threw an exception

Hibernate報錯:org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found :或者是org.hibernate.internal.util.config.ConfigurationException: Could not locate

可能原因:
1.在hibernate.cfg.xml檔案引用出錯
我的檔案引用是這樣的

        <mapping resource="com/entity/Product.hbm.xml"/>
        <mapping class="com.entity.Product"/>

而相對應的兩個對映檔案都在下圖檔案目錄下
在這裡插入圖片描述
2.之前我另一個專案出現過一種情況,即我這樣設定檔案和目錄位置還是報上述錯誤,所以我把其中resource的對映檔案改成

 		<mapping resource="Product.hbm.xml"/>

同時把該檔案移動到resources目錄下
在這裡插入圖片描述

解決問題(出現其餘bug)

org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.mysql.jdbc.Driver]

可能原因:
1.沒有匯入jdbc驅動包
(不過個人覺得應該不會這麼粗心吧)
2.資料庫沒有設定主鍵,一定要設定啊啊啊
在這裡插入圖片描述
3.jsp引用的時候沒有寫對 比如我的資料庫內容是id,但是在寫jsp的時候寫成了number
在這裡插入圖片描述
4.資料庫名字錯誤
   資料庫在建立的時候不能以中文,數字開頭,否則在引用的時候會報錯(不過錯誤的名字好像不是這個)

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

這句話總是報錯,因為同時期其他錯誤特別多我就沒管了,但是實際上在解決了其他問題的時候這個問題就沒有報錯了,所以按道理來說是沒有問題的。僅限於hibernate 5.x 版本,每個版本都不太一樣


後面問題會持續更新(有些問題因為解決了忘記記錄就算了)讓我感覺我就是個bug.jpg