知识大全 Hibernate的两种配置文件格式

Posted 文件

篇首语:知识为进步之母,而进步又为富强之源泉。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 Hibernate的两种配置文件格式相关的知识,希望对你有一定的参考价值。

Hibernate的两种配置文件格式  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  Hibernate有两种配置文件格式 一种是XML 默认为hibernate cfg xml 一种是properties 默认为hibernate properties不同的配置文件 Hibernate有两种配置文件格式 一种是XML 默认为hibernate cfg xml 一种是properties 默认为hibernate properties

  不同的配置文件 对Hibernate的初始化方法是不一样的

  比如 如果采用properties文件作为配置文件

  那么初始化的代码大致为

  Configuration config = new Configuration();

  config addClass(myclass class);

    如果配置文件为XML 则

  Configuration config = new Configuration(nfig();

  XML文件格式的配置文件不支持addClass方法!!!这是因为在配置文件XML文件中 已经定义了Mpaaing文件 因此就不需要在用编码方式导入POJO文件了

  另 网上好多文章 甚至有的书都说 Hibenate的配置文件必须放在class的根目录 参考一下API 发现这个说法是不正确的 例如Configuration config = new Configuration() config(配置文件名) 完全可以的

  所有config方法如下

   addCacheableFile(File xmlFile)

  If a cached xmlFile + bin exists and is newer than xmlFile the bin file will be read directly

   Configuration addClass(Class persistentClass) Read a mapping from an application resource using a convention

   Configuration addDirectory(File dir) Read all mapping documents from a directory tree

   Configuration addDocument( w c dom Document doc) Read mappings from a DOM Document

   Configuration addFile(File xmlFile) Read mappings from a particular XML file

   Configuration addFile(String xmlFile) Read mappings from a particular XML file

   void addFilterDefinition(FilterDefinition definition)

   Configuration addInputStream(InputStream xmlInputStream) Read mappings from an InputStream

   Configuration addJar(File jar) Read all mappings from a jar file

   Configuration addProperties(Properties extraProperties) Set the given properties

   Configuration addResource(String path) Read mappings from an application resource trying different classloaders

   Configuration addResource(String path ClassLoader classLoader) Read mappings from an application resource

   Configuration addURL(URL url) Read mappings from a URL

cha138/Article/program/Java/ky/201311/27883

相关参考

知识大全 连接Oracle数据库的Hibernate配置文件

连接Oracle数据库的Hibernate配置文件  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 hibernate.cfg.xml配置文件的说明

     在Eclipse中利用HibernateSynchronizer插件进行数据库表的映射数据查询和获取数据可以节省大量时间加速Hibernat

知识大全 hibernate二级缓存

  第一步添加二级缓存配置文件ehcachexml到项目的src目录  ehcachexml文件可以在hibernatereleaseFinal\\project\\etc目录下找到  第二步配置hi

知识大全 VB中文件操作的两种方式

VB中文件操作的两种方式  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  文本文件的操作  此种方

知识大全 用JSP实现上传文件的两种方法

用JSP实现上传文件的两种方法  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  以前用cos作文件

知识大全 解析PHP实现下载文件的两种方法

解析PHP实现下载文件的两种方法  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!本篇文章是对使用PH

知识大全 hibernate3二级缓存的配置及测试

配置ehcachexml文件放到classpath下 <?xmlversion=encoding=GBK?>     <e

知识大全 spring中读取xml配置文件、获取bean

  读取xml文件  /**  *利用XmlBeanFactory(Resourceresource)  *这里Resource必须是xml格式  *Resource包括AbstractResourc

油菜套种的两种模式

套冬菜、西瓜接茬水稻  该模式充分利用了油稻两季接茬间的光热能和土地资源,增加复种指数,通常亩产油菜籽120公斤;冬菜1000公斤;西瓜2200公斤;水稻450公斤。  1、配置方式:油菜移栽前将大田

油菜套种的两种模式

套冬菜、西瓜接茬水稻  该模式充分利用了油稻两季接茬间的光热能和土地资源,增加复种指数,通常亩产油菜籽120公斤;冬菜1000公斤;西瓜2200公斤;水稻450公斤。  1、配置方式:油菜移栽前将大田