📄 performance.po
字号:
msgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: http://bugs.kde.org\n""POT-Creation-Date: 2008-08-14 15:28+0000\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <LL@li.org>\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"#. Tag: title#: performance.xml:29#, no-c-formatmsgid "Improving performance"msgstr "提升性能"#. Tag: title#: performance.xml:32#, no-c-formatmsgid "Fetching strategies"msgstr "抓取策略(Fetching strategies)"#. Tag: para#: performance.xml:34#, no-c-formatmsgid """A <emphasis>fetching strategy</emphasis> is the strategy Hibernate will use ""for retrieving associated objects if the application needs to navigate the ""association. Fetch strategies may be declared in the O/R mapping metadata, ""or over-ridden by a particular HQL or <literal>Criteria</literal> query."msgstr """<emphasis>抓取策略(fetching strategy)</emphasis> 是指:当应用程序需要在""(Hibernate实体对象图的)关联关系间进行导航的时候, Hibernate如何获取关联对象""的策略。抓取策略可以在O/R映射的元数据中声明,也可以在特定的HQL 或<literal>条""件查询(Criteria Query)</literal>中重载声明。"#. Tag: para#: performance.xml:41#, no-c-formatmsgid "Hibernate3 defines the following fetching strategies:"msgstr "Hibernate3 定义了如下几种抓取策略:"#. Tag: para#: performance.xml:47#, no-c-formatmsgid """<emphasis>Join fetching</emphasis> - Hibernate retrieves the associated ""instance or collection in the same <literal>SELECT</literal>, using an ""<literal>OUTER JOIN</literal>."msgstr """<emphasis>连接抓取(Join fetching)</emphasis> - Hibernate通过 在""<literal>SELECT</literal>语句使用<literal>OUTER JOIN</literal>(外连接)来 获""得对象的关联实例或者关联集合。"#. Tag: para#: performance.xml:54#, no-c-formatmsgid """<emphasis>Select fetching</emphasis> - a second <literal>SELECT</literal> is ""used to retrieve the associated entity or collection. Unless you explicitly ""disable lazy fetching by specifying <literal>lazy=\"false\"</literal>, this ""second select will only be executed when you actually access the association."msgstr """<emphasis>查询抓取(Select fetching)</emphasis> - 另外发送一条 ""<literal>SELECT</literal> 语句抓取当前对象的关联实体或集合。除非你显式的指定""<literal>lazy=\"false\"</literal>禁止 延迟抓取(lazy fetching),否则只有当你""真正访问关联关系的时候,才会执行第二条select语句。"#. Tag: para#: performance.xml:63#, no-c-formatmsgid """<emphasis>Subselect fetching</emphasis> - a second <literal>SELECT</literal> ""is used to retrieve the associated collections for all entities retrieved in ""a previous query or fetch. Unless you explicitly disable lazy fetching by ""specifying <literal>lazy=\"false\"</literal>, this second select will only ""be executed when you actually access the association."msgstr """<emphasis>子查询抓取(Subselect fetching)</emphasis> - 另外发送一条""<literal>SELECT</literal> 语句抓取在前面查询到(或者抓取到)的所有实体对象的""关联集合。除非你显式的指定<literal>lazy=\"false\"</literal> 禁止延迟抓取""(lazy fetching),否则只有当你真正访问关联关系的时候,才会执行第二条select语""句。"#. Tag: para#: performance.xml:72#, no-c-formatmsgid """<emphasis>Batch fetching</emphasis> - an optimization strategy for select ""fetching - Hibernate retrieves a batch of entity instances or collections in ""a single <literal>SELECT</literal>, by specifying a list of primary keys or ""foreign keys."msgstr """<emphasis>批量抓取(Batch fetching)</emphasis> - 对查询抓取的优化方案, 通过""指定一个主键或外键列表,Hibernate使用单条<literal>SELECT</literal>语句获取一""批对象实例或集合。"#. Tag: para#: performance.xml:81#, no-c-formatmsgid "Hibernate also distinguishes between:"msgstr "Hibernate会区分下列各种情况:"#. Tag: para#: performance.xml:87#, no-c-formatmsgid """<emphasis>Immediate fetching</emphasis> - an association, collection or ""attribute is fetched immediately, when the owner is loaded."msgstr """<emphasis>Immediate fetching,立即抓取</emphasis> - 当宿主被加载时,关联、集""合或属性被立即抓取。"#. Tag: para#: performance.xml:93#, no-c-formatmsgid """<emphasis>Lazy collection fetching</emphasis> - a collection is fetched when ""the application invokes an operation upon that collection. (This is the ""default for collections.)"msgstr """<emphasis>Lazy collection fetching,延迟集合抓取</emphasis>- 直到应用程序对集""合进行了一次操作时,集合才被抓取。(对集合而言这是默认行为。)"#. Tag: para#: performance.xml:100#, no-c-formatmsgid """<emphasis>\"Extra-lazy\" collection fetching</emphasis> - individual ""elements of the collection are accessed from the database as needed. ""Hibernate tries not to fetch the whole collection into memory unless ""absolutely needed (suitable for very large collections)"msgstr """<emphasis>\"Extra-lazy\" collection fetching,\"Extra-lazy\"集合抓取</""emphasis> -对集合类中的每个元素而言,都是直到需要时才去访问数据库。除非绝对必""要,Hibernate不会试图去把整个集合都抓取到内存里来(适用于非常大的集合)。"#. Tag: para#: performance.xml:108#, no-c-formatmsgid """<emphasis>Proxy fetching</emphasis> - a single-valued association is fetched ""when a method other than the identifier getter is invoked upon the ""associated object."msgstr """<emphasis>Proxy fetching,代理抓取</emphasis> - 对返回单值的关联而言,当其某""个方法被调用,而非对其关键字进行get操作时才抓取。"#. Tag: para#: performance.xml:115#, no-c-formatmsgid """<emphasis>\"No-proxy\" fetching</emphasis> - a single-valued association is ""fetched when the instance variable is accessed. Compared to proxy fetching, ""this approach is less lazy (the association is fetched even when only the ""identifier is accessed) but more transparent, since no proxy is visible to ""the application. This approach requires buildtime bytecode instrumentation ""and is rarely necessary."msgstr """<emphasis>\"No-proxy\" fetching,非代理抓取</emphasis> - 对返回单值的关联而""言,当实例变量被访问的时候进行抓取。与上面的代理抓取相比,这种方法没有那么“延""迟”得厉害(就算只访问标识符,也会导致关联抓取)但是更加透明,因为对应用程序来""说,不再看到proxy。这种方法需要在编译期间进行字节码增强操作,因此很少需要用""到。"#. Tag: para#: performance.xml:125#, no-c-formatmsgid """<emphasis>Lazy attribute fetching</emphasis> - an attribute or single valued ""association is fetched when the instance variable is accessed. This approach ""requires buildtime bytecode instrumentation and is rarely necessary."msgstr """<emphasis>Lazy attribute fetching,属性延迟加载</emphasis> - 对属性或返回单值""的关联而言,当其实例变量被访问的时候进行抓取。需要编译期字节码强化,因此这一""方法很少是必要的。"#. Tag: para#: performance.xml:134#, no-c-formatmsgid """We have two orthogonal notions here: <emphasis>when</emphasis> is the ""association fetched, and <emphasis>how</emphasis> is it fetched (what SQL is ""used). Don't confuse them! We use <literal>fetch</literal> to tune ""performance. We may use <literal>lazy</literal> to define a contract for ""what data is always available in any detached instance of a particular class."msgstr """这里有两个正交的概念:关联<emphasis>何时</emphasis>被抓取,以及被<emphasis>如""何</emphasis>抓取(会采用什么样的SQL语句)。不要混淆它们!我们使用<literal>抓""取</literal>来改善性能。我们使用<literal>延迟</literal>来定义一些契约,对某特""定类的某个脱管的实例,知道有哪些数据是可以使用的。"#. Tag: title#: performance.xml:143#, no-c-formatmsgid "Working with lazy associations"msgstr "操作延迟加载的关联"#. Tag: para#: performance.xml:145#, no-c-formatmsgid """By default, Hibernate3 uses lazy select fetching for collections and lazy ""proxy fetching for single-valued associations. These defaults make sense for ""almost all associations in almost all applications."msgstr """默认情况下,Hibernate 3对集合使用延迟select抓取,对返回单值的关联使用延迟代理""抓取。对几乎是所有的应用而言,其绝大多数的关联,这种策略都是有效的。"#. Tag: para#: performance.xml:151#, no-c-formatmsgid """<emphasis>Note:</emphasis> if you set <literal>hibernate.""default_batch_fetch_size</literal>, Hibernate will use the batch fetch ""optimization for lazy fetching (this optimization may also be enabled at a ""more granular level)."msgstr """<emphasis>注意:</emphasis>假若你设置了<literal>hibernate.""default_batch_fetch_size</literal>,Hibernate会对延迟加载采取批量抓取优化措施""(这种优化也可能会在更细化的级别打开)。"#. Tag: para#: performance.xml:158#, no-c-formatmsgid """However, lazy fetching poses one problem that you must be aware of. Access ""to a lazy association outside of the context of an open Hibernate session ""will result in an exception. For example:"msgstr """然而,你必须了解延迟抓取带来的一个问题。在一个打开的Hibernate session上下文之""外调用延迟集合会导致一次意外。比如:"#. Tag: programlisting#: performance.xml:164#, no-c-formatmsgid """<![CDATA[s = sessions.openSession();\n""Transaction tx = s.beginTransaction();\n"" \n""User u = (User) s.createQuery(\"from User u where u.name=:userName\")\n"" .setString(\"userName\", userName).uniqueResult();\n""Map permissions = u.getPermissions();\n""\n""tx.commit();\n""s.close();\n""\n""Integer accessLevel = (Integer) permissions.get(\"accounts\"); // Error!]]>"msgstr ""#. Tag: para#: performance.xml:166#, no-c-formatmsgid """Since the permissions collection was not initialized when the ""<literal>Session</literal> was closed, the collection will not be able to ""load its state. <emphasis>Hibernate does not support lazy initialization for ""detached objects</emphasis>. The fix is to move the code that reads from the ""collection to just before the transaction is committed."msgstr """在<literal>Session</literal>关闭后,permessions集合将是未实例化的、不再可用,""因此无法正常载入其状态。 <emphasis>Hibernate对脱管对象不支持延迟实例化</""emphasis>. 这里的修改方法是:将permissions读取数据的代码 移到tx.commit()之""前。"#. Tag: para#: performance.xml:174#, no-c-formatmsgid """Alternatively, we could use a non-lazy collection or association, by ""specifying <literal>lazy=\"false\"</literal> for the association mapping. ""However, it is intended that lazy initialization be used for almost all ""collections and associations. If you define too many non-lazy associations ""in your object model, Hibernate will end up needing to fetch the entire ""database into memory in every transaction!"msgstr """除此之外,通过对关联映射指定<literal>lazy=\"false\"</literal>,我们也可以使用""非延迟的集合或关联。但是, 对绝大部分集合来说,更推荐使用延迟方式抓取数据。如""果在你的对象模型中定义了太多的非延迟关联,Hibernate最终几乎需要在每个事务中载""入整个数据库到内存中!"#. Tag: para#: performance.xml:183#, no-c-formatmsgid """On the other hand, we often want to choose join fetching (which is non-lazy ""by nature) instead of select fetching in a particular transaction. We'll now ""see how to customize the fetching strategy. In Hibernate3, the mechanisms ""for choosing a fetch strategy are identical for single-valued associations ""and collections."msgstr """但是,另一方面,在一些特殊的事务中,我们也经常需要使用到连接抓取(它本身上就""是非延迟的),以代替查询抓取。 下面我们将会很快明白如何具体的定制Hibernate中""的抓取策略。在Hibernate3中,具体选择哪种抓取策略的机制是和选择 单值关联或集合""关联相一致的。"#. Tag: title#: performance.xml:194#, no-c-formatmsgid "Tuning fetch strategies"msgstr "调整抓取策略(Tuning fetch strategies)"#. Tag: para#: performance.xml:196#, no-c-formatmsgid """Select fetching (the default) is extremely vulnerable to N+1 selects ""problems, so we might want to enable join fetching in the mapping document:"msgstr """查询抓取(默认的)在N+1查询的情况下是极其脆弱的,因此我们可能会要求在映射文档""中定义使用连接抓取:"#. Tag: programlisting#: performance.xml:201#, no-c-formatmsgid """<![CDATA[<set name=\"permissions\" \n"" fetch=\"join\">\n"" <key column=\"userId\"/>\n"" <one-to-many class=\"Permission\"/>\n""</set]]>"msgstr ""#. Tag: programlisting#: performance.xml:203#, no-c-formatmsgid "<![CDATA[<many-to-one name=\"mother\" class=\"Cat\" fetch=\"join\"/>]]>"msgstr ""#. Tag: para#: performance.xml:205#, no-c-formatmsgid ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -