日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Hibernate初始化經(jīng)驗總結(jié)

Hibernate還是比較常用的,于是我研究了一下Hibernate初始化,在這里拿出來和大家分享一下,希望對大家有用。

Hibernate有兩種配置文件格式,一種是XML,默認為hibernate.cfg.xml,一種是properties,默認為Hibernate.properties。不同的配置文件,對Hibernate初始化方法是不一樣的

比如,如果采用properties文件作為配置文件,那么Hibernate初始化的代碼大致為

 
 
 
  1. Configuration config = new Configuration();  
  2. config.addClass(myclass.class); 

如果配置文件為XML,則

 
 
 
  1. Configuration config = new Configuration().config(); 

XML文件格式的配置文件不支持addClass方法?。?!這是因為在配置文件XML文件中,已經(jīng)定義了Mpaaing文件,因此就不需要在用編碼方式導(dǎo)入POJO文件了。

另:網(wǎng)上好多文章,甚至有的書都說,Hibenate的配置文件必須放在class的根目錄,參考一下API,發(fā)現(xiàn)這個說法是不正確的,例如 Configuration config = new Configuration().config(配置文件名);完全可以的。

所有config方法如下:

 
 
 
  1. addCacheableFile(File xmlFile)  
  2.  
  3. If a cached xmlFile + ".bin" exists and is newer than xmlFile the ".
    bin" file will be read directly.  
  4.  
  5. Configuration addClass(Class persistentClass)  
  6. Read a mapping from an application resource, using a convention.  
  7.  
  8. Configuration addDirectory(File dir)  
  9. Read all mapping documents from a directory tree.  
  10.  
  11. Configuration addDocument(org.w3c.dom.Document doc)  
  12. Read mappings from a DOM Document  
  13.  
  14. Configuration addFile(File xmlFile)  
  15. Read mappings from a particular XML file  
  16.  
  17. Configuration addFile(String xmlFile)  
  18. Read mappings from a particular XML file  
  19.  
  20. void addFilterDefinition(FilterDefinition definition)  
  21.  
  22. Configuration addInputStream(InputStream xmlInputStream)  
  23. Read mappings from an InputStream  
  24.  
  25. Configuration addJar(File jar)  
  26. Read all mappings from a jar file  
  27.  
  28. Configuration addProperties(Properties extraProperties)  
  29. Set the given properties  
  30.  
  31. Configuration addResource(String path)  
  32. Read mappings from an application resource trying different classloaders.  
  33.  
  34. Configuration addResource(String path, ClassLoader classLoader)  
  35. Read mappings from an application resource  
  36.  
  37. Configuration addURL(URL url)  
  38. Read mappings from a URL  
  39.  
  40. Configuration addXML(String xml)  
  41. Read mappings from a String  

以上為筆者剛接觸Hibernate初始化的一個總結(jié),不正確的地方還請各位多多指教?。?/p>

【編輯推薦】

  1. 簡單描述Hibernate單元測試
  2. 概括Hibernate多表關(guān)聯(lián)查詢
  3. 淺談Hibernate Session Factory
  4. 淺析Hibernate加載配置文件
  5. 深入剖析Hibernate核心接口

新聞標題:Hibernate初始化經(jīng)驗總結(jié)
網(wǎng)址分享:http://m.5511xx.com/article/ccohojh.html