配置NHibernate

时间:2011-06-05 14:07:25

标签: nhibernate

我使用NHibernate的配置文件。 我想在同一个配置文件中定义多个session-factrory。 我是这样做的: `

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration"
 type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="test1">
  all properties
</session-factory>
  <session-factory name="test2">
  all properties
</session-factory>'

应用程序抛出异常: nhibernate.cfg.HibernateConfigException:解析配置时发生异常:元素'hibernate-configuration'具有无效的子元素'session-factory'

1 个答案:

答案 0 :(得分:3)

您无法在单个配置文件中定义两个会话工厂(架构不允许它,并且NHibernate无法提供访问它们的方法)

使用单独的文件,或者更好的是,使用一种更灵活的基于代码的方法。

请参阅http://fabiomaulo.blogspot.com/2009/07/nhibernate-fluent-configuration.htmlhttp://fabiomaulo.blogspot.com/2009/07/nhibernate-configuration-through.html