zoukankan      html  css  js  c++  java
  • NHibernate连接Oracle配置问题

    这几天在做NHibernate连接Oracle的测试,配置文件是从NHibernate发行包里拷贝出来的,做了简单的连接字符的修改,配置文件如下:

    复制代码
    代码
    <?xml version="1.0" encoding="utf-8"?>
    <!--
    This template was written to work with NHibernate.Test.
    Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
    for your own use before compile tests in VisualStudio.
    -->
    <!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->
    <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=xx;Password=xx;Data Source=xx;
    </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>
    <mapping assembly="Model"/>
    </session-factory>
    </hibernate-configuration>
    复制代码

    修改了两处内容:

    一修改dialect为NHibernate.Dialect.Oracle10gDialect,(我用的是oracle10g)原来的为NHibernate.Dialect.OracleDialect,不修改会提示映射文件不能编译,这个错误有点奇怪。

    二增加mapping节点,来指定映射文件所在程序集

    好了,简单的写个测试程序,再测试一下,OK测试能过。

    我们看到在配置文件中有一行:<!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->,这里使用的是微软提供的驱动程序,我们改成Oracle提供的试试。在配置文件中把 NHibernate.Driver.OracleClientDrivern改成 NHibernate.Driver.OracleDataClientDrivern。OK再测试,提示“Could not create the driver from NHibernate.Driver.OracleDataClientDriver.”,应该是我们没有添加Oracle.DataAccess的引用,我们来添加引用,很奇怪在添加程序集的窗口中的.Net选项卡,找不到,没有关系,我们在浏览选项卡里找,在“X:\oracle\product \10.2.0\client_1\BIN”目录下找到并选择Oracle.DataAccess.dll,再来做测试。还是提示“Could not create the driver from NHibernate.Driver.OracleDataClientDriver.”,我们找到Oracle.DataAccess.dll,拷贝到测试程序的bin目录下,再运行。这次还是报错,不过错误提示变了,“Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'.”,上网google了好久,没有找到解决办法,后来看到园友1-2-3在用NHibernate调用Oracle的存储过程 这篇文章找到了解决办法,在配置文件中增加一行:“<property name="hbm2ddl.keywords">none</property>”,再次执行我们的测试程序,这次执行通过。

    微软和Oracle都提供了.net连接Oracle数据库的驱动程序,一般认为Oracle所提供的驱动程序性能上要优于微软提供的。在.net4.0中使用System.Data.OracleClient时,会得到警告信息:“'System.Data.OracleClient.OracleConnection' is obsolete: 'OracleConnection has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260' ”,在给出的这个链接上有这么一句话:“The types in System.Data.OracleClient are deprecated. The types are supported in version 4 of the .NET Framework but will be removed in a future release. Microsoft recommends that you use a third-party Oracle provider.”意思是System.Data.OracleClient是不再被推荐使用的,并且在4.0以后的版本将被移除,微软推荐你使用 Oracle提供的驱动程序。

  • 相关阅读:
    Integer的十进制转二,八,十六进制
    Java内存模型
    python gui --tkinter
    图论-最短路径
    Java NIO
    浏览器关闭后,Session就销毁了吗?
    mysql查询最新一条数据
    MySQL 查看命令执行时间
    MySQL 删除devices表中id最大的一行
    MySQL中的联表查询与子查询
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/3035043.html
Copyright © 2011-2022 走看看