NHibernate - 在配置中找不到(oracle)方言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1073806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NHibernate - could not find (oracle) dialect in configuration
提问by Nigel
I've got following hibernate.cfg.xml
我有以下 hibernate.cfg.xml
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
User ID=user;Password=password;Data Source=database
</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
</session-factory>
Now I receive following error:
现在我收到以下错误:
failed: NHibernate.MappingException : Could not compile the mapping document: Mob.Icecube.Data.NH.Mappings.Customer.hbm.xml ----> System.InvalidOperationException : Could not find the dialect in the configuration
失败:NHibernate.MappingException:无法编译映射文档:Mob.Icecube.Data.NH.Mappings.Customer.hbm.xml ----> System.InvalidOperationException:在配置中找不到方言
Can anyone help me out why he cannot find the driver? Some extra info... It's running at the moment only inside a UnitTest application I added the NHibernate and System.Data.OracleClient to the references of the project Using the latest NHibernate version (2.2 beta)
谁能帮我看看为什么他找不到司机?一些额外的信息......它目前仅在 UnitTest 应用程序中运行我将 NHibernate 和 System.Data.OracleClient 添加到项目的引用中使用最新的 NHibernate 版本(2.2 测试版)
Thanks in advance
提前致谢
回答by Nigel
There is no NHibernate.Dialect.Oracle9Dialect dialect in the NHibernate assembly.
NHibernate 程序集中没有 NHibernate.Dialect.Oracle9Dialect 方言。
There is a NHibernate.Dialect.Oracle9iDialect.
有一个 NHibernate.Dialect.Oracle9iDialect。
Check that your NHibernate config file is being loaded correctly. Use something like:
检查您的 NHibernate 配置文件是否正确加载。使用类似的东西:
onfiguration config = new Configuration().Configure("hibernate.cfg.xml").
This is assuming your NHibernate configuration file is called hibernate.cfg.xml and is at the root of your application.
这是假设您的 NHibernate 配置文件名为 hibernate.cfg.xml 并且位于您的应用程序的根目录。
回答by Ronald
I registered myself now on the site, and it seems that at the moment I'm no longer allowed to leave any comments, so I'll just post the code again in a new answer :D
我现在在网站上注册了自己,现在似乎不再允许我发表任何评论,所以我将在新答案中再次发布代码:D
To create the config and factory: Configuration config = new Configuration(); config.AddAssembly("MyLib.Data.NH"); ISessionFactory factory = config.BuildSessionFactory();
创建配置和工厂:Configuration config = new Configuration(); config.AddAssembly("MyLib.Data.NH"); ISessionFactory factory = config.BuildSessionFactory();
I also changed the config now to use (what should be available) Oracle10gDialect (though I tried 9i as well without success).
我现在还更改了配置以使用(应该可用的)Oracle10gDialect(尽管我也尝试了 9i 没有成功)。
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
User ID=user;Password=password;Data Source=db
</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
</session-factory>
</hibernate-configuration>
回答by Mark Struzinski
Do you have the Oracle client installed locally on your pc? I believe this provides some drivers you may need to connect, but I'm not sure. If so, try copying the Oracle.DataAccess.dll file from your installation into the bin folder of your project. This has worked for me in the past.
您是否在您的 PC 上本地安装了 Oracle 客户端?我相信这提供了一些您可能需要连接的驱动程序,但我不确定。如果是这样,请尝试将 Oracle.DataAccess.dll 文件从您的安装复制到项目的 bin 文件夹中。这在过去对我有用。