hibernate學習手記(1)

來源:互聯網
上載者:User

標籤:文章   src   timezone   figure   rds   new   unknown   www   連接字串   

 

1. java.sql.SQLException: The server time zone value ‘?й???????‘ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configu 

出現該問題,是因為時區沒有指定,需要在連接字串上加上 serverTimezone=UTC

最終的連結語句是 jdbc:mysql:///demo-hibernate?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

 

2. org.hibernate.MappingException: Unknown entity: DBModel.Students 

出現該問題,有好幾個原因,有些是設定檔的引用問題,如果說我們在cfg.xml中點擊hbm.xml能跳轉到相應的檔案,說明引用沒問題。

我出現這個問題是應為hibernate的版本問題,類庫用的高版本,代碼裡面還是用的舊的寫法

我一開始是這麼寫的

 ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

後來看到這篇文章 http://www.imooc.com/wenda/detail/339079 改成了

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).configure().build();

問題就沒了

 

3.org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [*.hbm.xml]

這個錯誤是因為 cfg.xml檔案中<mapping  />的配置問題,檢查一下是不是有單詞拼字錯誤

 

4.org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : *.hbm.xml : origin(*.hbm.xml)

這個問題比較噁心,原來我配置原件都是放在src下面的 後來看了這篇文章  http://stackoverflow.com/questions/7127608/org-hibernate-mappingnotfoundexception-resource-hbm-xml-not-found 有所感悟,我看了下編譯後的檔案(traget檔案夾下)確實沒有hibernate的設定檔,後來加了一個 resources 檔案夾,把配置都放到該檔案下,再在build path添加一下就好了

 

hibernate學習手記(1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.