日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
淺析Hibernate配置文件

Hibernate有很多值得學(xué)習(xí)的地方,這里我們主要介紹Hibernate配置文件,包括介紹XML文件格式等方面。

創(chuàng)新互聯(lián)專注于商河網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供商河營銷型網(wǎng)站建設(shè),商河網(wǎng)站制作、商河網(wǎng)頁設(shè)計、商河網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務(wù),打造商河網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供商河網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

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

比如,如果采用properties文件作為Hibernate配置文件

那么初始化的代碼大致為

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

如果Hibernate配置文件為XML,則

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

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

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

所有config方法如下:

 
 
 
  1. addCacheableFile(File xmlFile)If a cached xmlFile + ".bin" 
    exists and is newer than xmlFile the ".bin" file will be read directly.  
  2. Configuration addClass(Class persistentClass) 
    Read a mapping from an application resource, using a convention.  
  3. Configuration addDirectory(File dir) 
    Read all mapping documents from a directory tree.   
  4. Configuration addDocument(org.w3c.dom.Document doc) 
    Read mappings from a DOM Document   
  5. Configuration addFile(File xmlFile) Read mappings from a particular XML file   
  6. Configuration addFile(String xmlFile) Read mappings from a particular XML file   
  7. void addFilterDefinition(FilterDefinition definition)  
  8. Configuration addInputStream(InputStream xmlInputStream) 
    Read mappings from an InputStream   
  9. Configuration addJar(File jar) Read all mappings from a jar file   
  10. Configuration addProperties(Properties extraProperties) Set the given properties   
  11. Configuration addResource(String path) 
    Read mappings from an application resource trying different classloaders.  
  12. Configuration addResource(String path, ClassLoader classLoader) 
    Read mappings from an application resource  
  13. Configuration addURL(URL url) Read mappings from a URL   
  14. Configuration addXML(String xml) Read mappings from a String 

文章名稱:淺析Hibernate配置文件
URL標題:http://www.dlmjj.cn/article/copidoo.html