⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 best_practices.po

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 PO
📖 第 1 页 / 共 2 页
字号:
msgstr "理解<literal>Session</literal>清洗( flushing)"#. Tag: para#: best_practices.xml:136#, no-c-formatmsgid """From time to time the Session synchronizes its persistent state with the ""database. Performance will be affected if this process occurs too often. You ""may sometimes minimize unnecessary flushing by disabling automatic flushing ""or even by changing the order of queries and other operations within a ""particular transaction."msgstr """Session会不时的向数据库同步持久化状态,如果这种操作进行的过于频繁,性能会受到""一定的影响。有时候你可以通过禁止自动flushing,尽量最小化非必要的flushing操""作,或者更进一步,在一个特定的transaction中改变查询和其它操作的顺序。"#. Tag: term#: best_practices.xml:145#, no-c-formatmsgid "In a three tiered architecture, consider using detached objects."msgstr "在三层结构中,考虑使用托管对象(detached object)"#. Tag: para#: best_practices.xml:147#, no-c-formatmsgid """When using a servlet / session bean architecture, you could pass persistent ""objects loaded in the session bean to and from the servlet / JSP layer. Use ""a new session to service each request. Use <literal>Session.merge()</""literal> or <literal>Session.saveOrUpdate()</literal> to synchronize objects ""with the database."msgstr """当使用一个servlet / session bean 类型的架构的时候, 你可以把已加载的持久对象在""session bean层和servlet / JSP 层之间来回传递。使用新的session来为每个请求服""务,使用 <literal>Session.merge()</literal> 或者<literal>Session.saveOrUpdate""()</literal>来与数据库同步。"#. Tag: term#: best_practices.xml:156#, no-c-formatmsgid "In a two tiered architecture, consider using long persistence contexts."msgstr "在两层结构中,考虑使用长持久上下文(long persistence contexts)."#. Tag: para#: best_practices.xml:158#, no-c-formatmsgid """Database Transactions have to be as short as possible for best scalability. ""However, it is often neccessary to implement long running ""<emphasis>application transactions</emphasis>, a single unit-of-work from ""the point of view of a user. An application transaction might span several ""client request/response cycles. It is common to use detached objects to ""implement application transactions. An alternative, extremely appropriate in ""two tiered architecture, is to maintain a single open persistence contact ""(session) for the whole life cycle of the application transaction and simply ""disconnect from the JDBC connection at the end of each request and reconnect ""at the beginning of the subsequent request. Never share a single session ""across more than one application transaction, or you will be working with ""stale data."msgstr """为了得到最佳的可伸缩性,数据库事务(Database Transaction)应该尽可能的短。但""是,程序常常需要实现长时间运行的<emphasis>“应用程序事务(Application ""Transaction)”</emphasis>,包含一个从用户的观点来看的原子操作。这个应用程序事""务可能跨越多次从用户请求到得到反馈的循环。用脱管对象(与session脱离的对象)来实""现应用程序事务是常见的。或者,尤其在两层结构中,把Hibernate Session从JDBC连接""中脱离开,下次需要用的时候再连接上。绝不要把一个Session用在多个应用程序事务""(Application Transaction)中,否则你的数据可能会过期失效。"#. Tag: term#: best_practices.xml:172#, no-c-formatmsgid "Don't treat exceptions as recoverable."msgstr "不要把异常看成可恢复的"#. Tag: para#: best_practices.xml:174#, no-c-formatmsgid """This is more of a necessary practice than a \"best\" practice. When an ""exception occurs, roll back the <literal>Transaction</literal> and close the ""<literal>Session</literal>. If you don't, Hibernate can't guarantee that in-""memory state accurately represents persistent state. As a special case of ""this, do not use <literal>Session.load()</literal> to determine if an ""instance with the given identifier exists on the database; use ""<literal>Session.get()</literal> or a query instead."msgstr """这一点甚至比“最佳实践”还要重要,这是“必备常识”。当异常发生的时候,必须要回滚 ""<literal>Transaction</literal> ,关闭<literal>Session</literal>。如果你不这样""做的话,Hibernate无法保证内存状态精确的反应持久状态。尤其不要使用""<literal>Session.load()</literal>来判断一个给定标识符的对象实例在数据库中是否""存在,应该使用<literal>Session.get()</literal>或者进行一次查询."#. Tag: term#: best_practices.xml:184#, no-c-formatmsgid "Prefer lazy fetching for associations."msgstr "对于关联优先考虑lazy fetching"#. Tag: para#: best_practices.xml:186#, no-c-formatmsgid """Use eager fetching sparingly. Use proxies and lazy collections for most ""associations to classes that are not likely to be completely held in the ""second-level cache. For associations to cached classes, where there is an a ""extremely high probability of a cache hit, explicitly disable eager fetching ""using <literal>lazy=\"false\"</literal>. When an join fetching is ""appropriate to a particular use case, use a query with a <literal>left join ""fetch</literal>."msgstr """谨慎的使用主动抓取(eager fetching)。对于关联来说,若其目标是无法在第二级缓存""中完全缓存所有实例的类,应该使用代理(proxies)与/或具有延迟加载属性的集合""(lazy collections)。若目标是可以被缓存的,尤其是缓存的命中率非常高的情况下,""应该使用<literal>lazy=\"false\"</literal>,明确的禁止掉eager fetching。如果那""些特殊的确实适合使用join fetch 的场合,请在查询中使用<literal>left join ""fetch</literal>。"#. Tag: term#: best_practices.xml:196#, no-c-formatmsgid """Use the <emphasis>open session in view</emphasis> pattern, or a disciplined ""<emphasis>assembly phase</emphasis> to avoid problems with unfetched data."msgstr """使用<emphasis>open session in view</emphasis>模式,或者执行严格的<emphasis>装""配期(assembly phase)</emphasis>策略来避免再次抓取数据带来的问题"#. Tag: para#: best_practices.xml:201#, no-c-formatmsgid """Hibernate frees the developer from writing tedious <emphasis>Data Transfer ""Objects</emphasis> (DTO). In a traditional EJB architecture, DTOs serve dual ""purposes: first, they work around the problem that entity beans are not ""serializable; second, they implicitly define an assembly phase where all ""data to be used by the view is fetched and marshalled into the DTOs before ""returning control to the presentation tier. Hibernate eliminates the first ""purpose. However, you will still need an assembly phase (think of your ""business methods as having a strict contract with the presentation tier ""about what data is available in the detached objects) unless you are ""prepared to hold the persistence context (the session) open across the view ""rendering process. This is not a limitation of Hibernate! It is a ""fundamental requirement of safe transactional data access."msgstr """Hibernate让开发者们摆脱了繁琐的<emphasis>Data Transfer Objects</emphasis> ""(DTO)。在传统的EJB结构中,DTO有双重作用:首先,他们解决了entity bean无法序列""化的问题;其次,他们隐含地定义了一个装配期,在此期间,所有在view层需要用到的""数据,都被抓取、集中到了DTO中,然后控制才被装到表示层。Hibernate终结了第一个""作用。然而,除非你做好了在整个渲染过程中都维护一个打开的持久化上下文(session)""的准备,你仍然需要一个装配期(想象一下,你的业务方法与你的表示层有严格的契""约,数据总是被放置到托管对象中)。这并非是Hibernate的限制!这是实现安全的事务""化数据访问的基本需求。"#. Tag: term#: best_practices.xml:215#, no-c-formatmsgid "Consider abstracting your business logic from Hibernate."msgstr "考虑把Hibernate代码从业务逻辑代码中抽象出来"#. Tag: para#: best_practices.xml:217#, no-c-formatmsgid """Hide (Hibernate) data-access code behind an interface. Combine the ""<emphasis>DAO</emphasis> and <emphasis>Thread Local Session</emphasis> ""patterns. You can even have some classes persisted by handcoded JDBC, ""associated to Hibernate via a <literal>UserType</literal>. (This advice is ""intended for \"sufficiently large\" applications; it is not appropriate for ""an application with five tables!)"msgstr """把Hibernate的数据存取代码隐藏到接口(interface)的后面,组合使用<emphasis>DAO</""emphasis>和<emphasis>Thread Local Session</emphasis>模式。通过Hibernate的""<literal>UserType</literal>,你甚至可以用硬编码的JDBC来持久化那些本该被""Hibernate持久化的类。 (该建议更适用于规模足够大应用软件中,对于那些只有5张表""的应用程序并不适合。)"#. Tag: term#: best_practices.xml:227#, no-c-formatmsgid "Don't use exotic association mappings."msgstr "不要用怪异的连接映射"#. Tag: para#: best_practices.xml:229#, no-c-formatmsgid """Good usecases for a real many-to-many associations are rare. Most of the ""time you need additional information stored in the \"link table\". In this ""case, it is much better to use two one-to-many associations to an ""intermediate link class. In fact, we think that most associations are one-to-""many and many-to-one, you should be careful when using any other association ""style and ask yourself if it is really neccessary."msgstr """多对多连接用得好的例子实际上相当少见。大多数时候你在“连接表”中需要保存额外的""信息。这种情况下,用两个指向中介类的一对多的连接比较好。实际上,我们认为绝大""多数的连接是一对多和多对一的,你应该谨慎使用其它连接风格,用之前问自己一句,""是否真的必须这么做。"#. Tag: term#: best_practices.xml:239#, no-c-formatmsgid "Prefer bidirectional associations."msgstr "偏爱双向关联"#. Tag: para#: best_practices.xml:241#, no-c-formatmsgid """Unidirectional associations are more difficult to query. In a large ""application, almost all associations must be navigable in both directions in ""queries."msgstr """单向关联更加难于查询。在大型应用中,几乎所有的关联必须在查询中可以双向导航。"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -