📄 performance.po
字号:
"The <literal>fetch</literal> strategy defined in the mapping document ""affects:"msgstr """在映射文档中定义的<literal>抓取</literal>策略将会对以下列表条目产生影响:"#. Tag: para#: performance.xml:211#, no-c-formatmsgid "retrieval via <literal>get()</literal> or <literal>load()</literal>"msgstr "通过<literal>get()</literal>或<literal>load()</literal>方法取得数据。"#. Tag: para#: performance.xml:216#, no-c-formatmsgid "retrieval that happens implicitly when an association is navigated"msgstr "只有在关联之间进行导航时,才会隐式的取得数据。"#. Tag: para#: performance.xml:221#, no-c-formatmsgid "<literal>Criteria</literal> queries"msgstr "条件查询"#. Tag: para#: performance.xml:226#, no-c-formatmsgid "HQL queries if <literal>subselect</literal> fetching is used"msgstr "使用了<literal>subselect</literal>抓取的HQL查询"#. Tag: para#: performance.xml:232#, no-c-formatmsgid """No matter what fetching strategy you use, the defined non-lazy graph is ""guaranteed to be loaded into memory. Note that this might result in several ""immediate selects being used to execute a particular HQL query."msgstr """不管你使用哪种抓取策略,定义为非延迟的类图会被保证一定装载入内存。注意这可能""意味着在一条HQL查询后紧跟着一系列的查询。"#. Tag: para#: performance.xml:238#, no-c-formatmsgid """Usually, we don't use the mapping document to customize fetching. Instead, ""we keep the default behavior, and override it for a particular transaction, ""using <literal>left join fetch</literal> in HQL. This tells Hibernate to ""fetch the association eagerly in the first select, using an outer join. In ""the <literal>Criteria</literal> query API, you would use ""<literal>setFetchMode(FetchMode.JOIN)</literal>."msgstr """通常情况下,我们并不使用映射文档进行抓取策略的定制。更多的是,保持其默认值,""然后在特定的事务中, 使用HQL的<literal>左连接抓取(left join fetch)</""literal> 对其进行重载。这将通知 Hibernate在第一次查询中使用外部关联(outer ""join),直接得到其关联数据。 在<literal>条件查询</literal> API中,应该调用 ""<literal>setFetchMode(FetchMode.JOIN)</literal>语句。"#. Tag: para#: performance.xml:247#, no-c-formatmsgid """If you ever feel like you wish you could change the fetching strategy used ""by <literal>get()</literal> or <literal>load()</literal>, simply use a ""<literal>Criteria</literal> query, for example:"msgstr """也许你喜欢仅仅通过条件查询,就可以改变<literal>get()</literal> 或 ""<literal>load()</literal>语句中的数据抓取策略。例如:"#. Tag: programlisting#: performance.xml:253#, no-c-formatmsgid """<![CDATA[User user = (User) session.createCriteria(User.class)\n"" .setFetchMode(\"permissions\", FetchMode.JOIN)\n"" .add( Restrictions.idEq(userId) )\n"" .uniqueResult();]]>"msgstr ""#. Tag: para#: performance.xml:255#, no-c-formatmsgid """(This is Hibernate's equivalent of what some ORM solutions call a \"fetch ""plan\".)"msgstr """(这就是其他ORM解决方案的“抓取计划(fetch plan)”在Hibernate中的等价物。)"#. Tag: para#: performance.xml:259#, no-c-formatmsgid """A completely different way to avoid problems with N+1 selects is to use the ""second-level cache."msgstr "截然不同的一种避免N+1次查询的方法是,使用二级缓存。"#. Tag: title#: performance.xml:267#, no-c-formatmsgid "Single-ended association proxies"msgstr "单端关联代理(Single-ended association proxies)"#. Tag: para#: performance.xml:269#, no-c-formatmsgid """Lazy fetching for collections is implemented using Hibernate's own ""implementation of persistent collections. However, a different mechanism is ""needed for lazy behavior in single-ended associations. The target entity of ""the association must be proxied. Hibernate implements lazy initializing ""proxies for persistent objects using runtime bytecode enhancement (via the ""excellent CGLIB library)."msgstr """在Hinerbate中,对集合的延迟抓取的采用了自己的实现方法。但是,对于单端关联的延""迟抓取,则需要采用 其他不同的机制。单端关联的目标实体必须使用代理,Hihernate""在运行期二进制级(通过优异的CGLIB库), 为持久对象实现了延迟载入代理。"#. Tag: para#: performance.xml:277#, no-c-formatmsgid """By default, Hibernate3 generates proxies (at startup) for all persistent ""classes and uses them to enable lazy fetching of <literal>many-to-one</""literal> and <literal>one-to-one</literal> associations."msgstr """默认的,Hibernate3将会为所有的持久对象产生代理(在启动阶段),然后使用他们实""现 <literal>多对一(many-to-one)</literal>关联和<literal>一对一(one-to-""one)</literal> 关联的延迟抓取。"#. Tag: para#: performance.xml:283#, no-c-formatmsgid """The mapping file may declare an interface to use as the proxy interface for ""that class, with the <literal>proxy</literal> attribute. By default, ""Hibernate uses a subclass of the class. <emphasis>Note that the proxied ""class must implement a default constructor with at least package visibility. ""We recommend this constructor for all persistent classes!</emphasis>"msgstr """在映射文件中,可以通过设置<literal>proxy</literal>属性为目标class声明一个接口""供代理接口使用。 默认的,Hibernate将会使用该类的一个子类。 <emphasis>注意:被""代理的类必须实现一个至少包可见的默认构造函数,我们建议所有的持久类都应拥有这""样的构造函数</emphasis>"#. Tag: para#: performance.xml:290#, no-c-formatmsgid """There are some gotchas to be aware of when extending this approach to ""polymorphic classes, eg."msgstr "在如此方式定义一个多态类的时候,有许多值得注意的常见性的问题,例如:"#. Tag: programlisting#: performance.xml:295#, no-c-formatmsgid """<![CDATA[<class name=\"Cat\" proxy=\"Cat\">\n"" ......\n"" <subclass name=\"DomesticCat\">\n"" .....\n"" </subclass>\n""</class>]]>"msgstr ""#. Tag: para#: performance.xml:297#, no-c-formatmsgid """Firstly, instances of <literal>Cat</literal> will never be castable to ""<literal>DomesticCat</literal>, even if the underlying instance is an ""instance of <literal>DomesticCat</literal>:"msgstr """首先,<literal>Cat</literal>实例永远不可以被强制转换为<literal>DomesticCat</""literal>, 即使它本身就是<literal>DomesticCat</literal>实例。"#. Tag: programlisting#: performance.xml:303#, no-c-formatmsgid """<![CDATA[Cat cat = (Cat) session.load(Cat.class, id); // instantiate a ""proxy (does not hit the db)\n""if ( cat.isDomesticCat() ) { // hit the db to initialize ""the proxy\n"" DomesticCat dc = (DomesticCat) cat; // Error!\n"" ....\n""}]]>"msgstr ""#. Tag: para#: performance.xml:305#, no-c-formatmsgid "Secondly, it is possible to break proxy <literal>==</literal>."msgstr "其次,代理的“<literal>==</literal>”可能不再成立。"#. Tag: programlisting#: performance.xml:309#, no-c-formatmsgid """<![CDATA[Cat cat = (Cat) session.load(Cat.class, id); // ""instantiate a Cat proxy\n""DomesticCat dc = \n"" (DomesticCat) session.load(DomesticCat.class, id); // acquire new ""DomesticCat proxy!\n""System.out.println(cat==dc); // false]]>"msgstr ""#. Tag: para#: performance.xml:311#, no-c-formatmsgid """However, the situation is not quite as bad as it looks. Even though we now ""have two references to different proxy objects, the underlying instance will ""still be the same object:"msgstr """虽然如此,但实际情况并没有看上去那么糟糕。虽然我们现在有两个不同的引用,分别""指向这两个不同的代理对象, 但实际上,其底层应该是同一个实例对象:"#. Tag: programlisting#: performance.xml:316#, no-c-formatmsgid """<![CDATA[cat.setWeight(11.0); // hit the db to initialize the proxy\n""System.out.println( dc.getWeight() ); // 11.0]]>"msgstr ""#. Tag: para#: performance.xml:318#, no-c-formatmsgid """Third, you may not use a CGLIB proxy for a <literal>final</literal> class or ""a class with any <literal>final</literal> methods."msgstr "第三,你不能对“final类”或“具有final方法的类”使用CGLIB代理。"#. Tag: para#: performance.xml:323#, no-c-formatmsgid """Finally, if your persistent object acquires any resources upon instantiation ""(eg. in initializers or default constructor), then those resources will also ""be acquired by the proxy. The proxy class is an actual subclass of the ""persistent class."msgstr """最后,如果你的持久化对象在实例化时需要某些资源(例如,在实例化方法、默认构造""方法中), 那么代理对象也同样需要使用这些资源。实际上,代理类是持久化类的子""类。"#. Tag: para#: performance.xml:329#, no-c-formatmsgid """These problems are all due to fundamental limitations in Java's single ""inheritance model. If you wish to avoid these problems your persistent ""classes must each implement an interface that declares its business methods. ""You should specify these interfaces in the mapping file. eg."msgstr """这些问题都源于Java的单根继承模型的天生限制。如果你希望避免这些问题,那么你的""每个持久化类必须实现一个接口, 在此接口中已经声明了其业务方法。然后,你需要在""映射文档中再指定这些接口。例如:"#. Tag: programlisting#: performance.xml:335#, no-c-formatmsgid """<![CDATA[<class name=\"CatImpl\" proxy=\"Cat\">\n"" ......\n"" <subclass name=\"DomesticCatImpl\" proxy=\"DomesticCat\">\n"" .....\n"" </subclass>\n""</class>]]>"msgstr ""#. Tag: para#: performance.xml:337#, no-c-formatmsgid """where <literal>CatImpl</literal> implements the interface <literal>Cat</""literal> and <literal>DomesticCatImpl</literal> implements the interface ""<literal>DomesticCat</literal>. Then proxies for instances of <literal>Cat</""literal> and <literal>DomesticCat</literal> may be returned by <literal>load""()</literal> or <literal>iterate()</literal>. (Note that <literal>list()</""literal> does not usually return proxies.)"msgstr """这里<literal>CatImpl</literal>实现了<literal>Cat</literal>接口, ""<literal>DomesticCatImpl</literal>实现<literal>DomesticCat</literal>接口。 在""<literal>load()</literal>、<literal>iterate()</literal>方法中就会返回 ""<literal>Cat</literal>和<literal>DomesticCat</literal>的代理对象。 (注意""<literal>list()</literal>并不会返回代理对象。)"#. Tag: programlisting#: performance.xml:345#, no-c-formatmsgid """<![CDATA[Cat cat = (Cat) session.load(CatImpl.class, catid);\n""Iterator iter = session.createQuery(\"from CatImpl as cat where cat.""name='fritz'\").iterate();\n""Cat fritz = (Cat) iter.next();]]>"msgstr ""#. Tag: para#: performance.xml:347#, no-c-formatmsgid """Relationships are also lazily initialized. This means you must declare any ""properties to be of type <literal>Cat</literal>, not <literal>CatImpl</""literal>."msgstr """这里,对象之间的关系也将被延迟载入。这就意味着,你应该将属性声明为""<literal>Cat</literal>,而不是<literal>CatImpl</literal>。"#. Tag: para#: performance.xml:352#, no-c-formatmsgid """Certain operations do <emphasis>not</emphasis> require proxy initialization"msgstr "但是,在有些方法中是<emphasis>不需要</emphasis>使用代理的。例如:"#. Tag: para#: performance.xml:358#, no-c-formatmsgid """<literal>equals()</literal>, if the persistent class does not override ""<literal>equals()</literal>"msgstr """<literal>equals()</literal>方法,如果持久类没有重载<literal>equals()</""literal>方法。"#. Tag: para#: performance.xml:364#, no-c-formatmsgid """<literal>hashCode()</literal>, if the persistent class does not override ""<literal>hashCode()</literal>"msgstr """<literal>hashCode()</literal>方法,如果持久类没有重载<literal>hashCode()</""literal>方法。"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -