自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺析Hibernate配置文件

開發(fā) 后端
這里介紹有兩種Hibernate配置文件格式,一種是XML,默認(rèn)為Hibernate.cfg.xml,一種是properties,默認(rèn)為Hibernate.properties不同的配置文件,對Hibernate的初始化方法是不一樣的。

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

有兩種Hibernate配置文件格式,一種是XML,默認(rèn)為Hibernate.cfg.xml,一種是properties,默認(rèn)為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方法?。?!這是因?yàn)樵贖ibernate配置文件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 

【編輯推薦】

  1. Hibernate可行性全面概括
  2. Hibernate Sequence基礎(chǔ)描述
  3. 淺析Hibernate使用EhCache
  4. Hibernate的一級Cache
  5. Hibernate update淺談
責(zé)任編輯:佚名 來源: Sina
相關(guān)推薦

2009-09-25 10:49:25

Hibernate加載

2009-09-29 15:52:26

Hibernate X

2009-09-29 17:29:43

Hibernate S

2009-09-27 13:25:22

2009-08-13 09:16:57

C#讀取配置文件

2012-02-06 13:34:49

HibernateJava

2009-07-21 10:05:10

ASP.NET配置文件

2009-09-24 10:07:21

Hibernate M

2009-09-22 14:44:18

Hibernate.c

2009-08-05 10:57:17

ASP.NET配置文件配置文件格式

2009-06-23 18:19:32

單元測試Hibernate配置

2009-06-02 14:12:26

Hibernate配置文件格式

2009-09-28 17:23:51

Hibernate E

2009-08-05 11:16:26

ASP.NET配置文件

2009-09-21 18:13:11

Hibernate S

2009-09-23 17:28:55

Hibernate C

2009-09-23 10:19:08

Hibernate分頁

2009-09-21 12:50:34

Hibernate架構(gòu)

2009-09-21 17:23:49

Hibernate使用

2009-09-22 13:09:06

Hibernateorm框架
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號