日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

不同配置文件的初始化Hibernate心得

 WindySky 2007-10-10
Hibernate有兩種配置文件格式,一種是XML,默認(rèn)為hibernate.cfg.xml,一種是properties,默認(rèn)為hibernate.properties

不同的配置文件,對(duì)Hibernate的初始化方法是不一樣的

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

那么初始化的代碼大致為

Configuration config = new Configuration();

config.addClass(myclass.class);

如果配置文件為XML,則

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

    XML文件格式的配置文件不支持addClass方法?。。∵@是因?yàn)樵谂渲梦募ML文件中,已經(jīng)定義了Mpaaing文件,因此就不需要在用編碼方式導(dǎo)入POJO文件了。

    另:網(wǎng)上好多文章,甚至有的書都說,Hibenate的配置文件必須放在class的根目錄,參考一下API,發(fā)現(xiàn)這個(gè)說法是不正確的,例如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的一個(gè)總結(jié),不正確的地方還請(qǐng)各位多多指教??!

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多