加快NHibernate对Oracle的呼叫? [英] Speed up NHibernate Calls to Oracle?

查看:96
本文介绍了加快NHibernate对Oracle的呼叫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用NHibernate连接到Oracle时是否需要考虑优化?我打给Oracle的电话花了很长时间.如果我直接针对Oracle运行NHibernate查询(从Visual Studio的输出窗口复制),它很快就会返回.这是我的NHibernate配置文件.如果需要,我可以发布映射文件.

Are there any optimizations to consider when connecting to Oracle with NHibernate? My calls to Oracle are taking an extremely long time. If I run the NHibernate query (copied from my output window in Visual Studio) directly against Oracle, it comes right back in under a second. Here is my config file for NHibernate. I can post the mapping files if needed.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="DefaultSessionFactory">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.OracleDialect</property>
        <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
        <property name="connection.connection_string">Data Source=****;Persist Security Info=True;User ID=******;Password=*******;Unicode=True</property>
        <property name="show_sql">true</property>
        <mapping assembly="AQTool.BL"/>
    </session-factory>
</hibernate-configuration>

更新: 在这里总结所有讨论:

Update: summarizing all the discussion here:

如果我删除所有多对一关系,并且仅对没有连接的单个实体运行单元测试,则查询仍将运行2分钟以上.如果我复制nhibernate生成的sql并直接针对oracle运行它,查询将在不到一秒的时间内返回.我也在这里发布我的映射文件.我是否缺少任何可能导致这种差异的信息?我唯一要做的就是按帐户ID进行选择.尽管表很大(超过5M行),但已为客户帐户ID字段建立了索引,并且原始查询很快返回.

If I remove all the many-to-one relationships and just run my unit test against the single entity with no joins, the query still runs for over 2 minutes. If I copy the sql generated by nhibernate and run it directly against oracle, the query returns in under a second. I am posting my mapping file here as well. Is there anything I am missing that might be causing this disparity? The only thing I am doing is selecting by Account Id. Although the table is large (over 5M rows), the customer account id field is indexed, and the raw query comes back very quickly.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="AQTool.BL" assembly="AQTool.BL" default-lazy="true">
    <class name="AQTool.BL.EmailAddress,AQTool.BL" table="EMAIL_CUSTOMER_ADDRESSES">
        <id name="EmailAddressId" column="EMAIL_ADDRESS_ID" type="int">
            <generator class="native" />
        </id>
        <property name="CustomerAccountId" column="CUSTOMER_ACCOUNT_ID" type="string" />
        <property name="EmailAddressText" column="EMAIL_ADDRESS_TX" type="string" />
        <property name="EmailAddressTypeId" column="EMAIL_ADDRESS_TYPE_ID" type="int" />
        <property name="EmailAddressTypeIdInternal" column="EMAIL_ADDRESS_TYPE_ID_INTERNAL" type="int" />

    </class>
</hibernate-mapping>

推荐答案

您可以考虑使用此工具调试NHibernate" NHibernate查询分析器

You may consider using this tool for "debugging NHibernate" NHibernate Query Analyzer

这篇关于加快NHibernate对Oracle的呼叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆