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

Hibernate的兩種配置文件格式

開發(fā) 后端
不同配置文件的初始化Hibernate,一種是XML,默認(rèn)為hibernate.cfg.xml,一種是properties,默認(rèn)為hibernate.properties。

Hibernate有兩種配置文件格式,一種是XML,默認(rèn)為hibernate.cfg.xml,一種是properties,默認(rèn)為hibernate.properties不同的配置文件,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)上好多文章,甚至有的書都說(shuō),Hibenate的配置文件必須放在class的根目錄,參考一下API,發(fā)現(xiàn)這個(gè)說(shuō)法是不正確的,例如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的兩種配置文件格式

【編輯推薦】

  1. Hibernate/JPA成功使用的十點(diǎn)心得
  2. hibernate(jpa)復(fù)合主鍵annotation聲明方法
  3. 使用hibernate的11大優(yōu)勢(shì)
責(zé)任編輯:張攀 來(lái)源: 育龍網(wǎng)
相關(guān)推薦

2021-09-29 15:52:26

計(jì)算機(jī)配置文件語(yǔ)言

2009-08-05 10:57:17

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

2009-09-25 16:55:08

Hibernate初始

2009-09-22 10:23:15

Hibernate配置

2010-08-02 16:58:08

Flex配置文件

2009-06-23 18:18:13

SpringHibernate

2009-09-29 15:52:26

Hibernate X

2009-09-27 13:25:22

2009-09-29 17:29:43

Hibernate S

2009-09-25 10:49:25

Hibernate加載

2009-06-25 13:43:00

Buffalo AJA

2010-06-07 17:41:42

Sendmail 配置

2022-12-09 18:06:21

2012-02-06 13:34:49

HibernateJava

2019-11-18 09:00:10

大數(shù)據(jù)數(shù)據(jù)格式文件格式

2009-09-25 14:04:09

Hibernate eHibernate h

2012-05-29 09:06:32

Hadoop文件格式

2010-11-03 15:15:26

DB2數(shù)據(jù)移動(dòng)

2012-05-29 09:48:21

Hadoop

2016-12-01 14:47:20

點(diǎn)贊
收藏

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