📄 session_api.po
字号:
"use the JDBC <literal>Connection</literal> directly. If you chose to use the ""Hibernate API, you must enclose SQL aliases in braces:"msgstr """你可以使用<literal>createSQLQuery()</literal>方法,用SQL来描述查询,并由""Hibernate将结果集转换成对象。 请注意,你可以在任何时候调用<literal>session.""connection()</literal>来获得并使用JDBC <literal>Connection</literal>对象。 如""果你选择使用Hibernate的API, 你必须把SQL别名用大括号包围起来:"#. Tag: programlisting#: session_api.xml:492#, no-c-formatmsgid """<![CDATA[List cats = session.createSQLQuery(\"SELECT {cat.*} FROM CAT {cat} ""WHERE ROWNUM<10\")\n"" .addEntity(\"cat\", Cat.class)\n"".list();]]>"msgstr ""#. Tag: programlisting#: session_api.xml:494#, no-c-formatmsgid """<![CDATA[List cats = session.createSQLQuery(\n"" \"SELECT {cat}.ID AS {cat.id}, {cat}.SEX AS {cat.sex}, \" +\n"" \"{cat}.MATE AS {cat.mate}, {cat}.SUBCLASS AS {cat.class}, ... \" ""+\n"" \"FROM CAT {cat} WHERE ROWNUM<10\")\n"" .addEntity(\"cat\", Cat.class)\n"".list()]]>"msgstr ""#. Tag: para#: session_api.xml:496#, no-c-formatmsgid """SQL queries may contain named and positional parameters, just like Hibernate ""queries. More information about native SQL queries in Hibernate can be found ""in <xref linkend=\"querysql\"/>."msgstr """和Hibernate查询一样,SQL查询也可以包含命名参数和占位参数。 可以在<xref ""linkend=\"querysql\"/>找到更多关于Hibernate中原生SQL(native SQL)的信息。"#. Tag: title#: session_api.xml:507#, no-c-formatmsgid "Modifying persistent objects"msgstr "修改持久对象"#. Tag: para#: session_api.xml:509#, no-c-formatmsgid """<emphasis>Transactional persistent instances</emphasis> (ie. objects loaded, ""saved, created or queried by the <literal>Session</literal>) may be ""manipulated by the application and any changes to persistent state will be ""persisted when the <literal>Session</literal> is <emphasis>flushed</""emphasis> (discussed later in this chapter). There is no need to call a ""particular method (like <literal>update()</literal>, which has a different ""purpose) to make your modifications persistent. So the most straightforward ""way to update the state of an object is to <literal>load()</literal> it, and ""then manipulate it directly, while the <literal>Session</literal> is open:"msgstr """<emphasis>事务中的持久实例</emphasis>(就是通过<literal>session</literal>装""载、保存、创建或者查询出的对象) 被应用程序操作所造成的任何修改都会在""<literal>Session</literal>被<emphasis>刷出(flushed)</emphasis>的时候被持久""化(本章后面会详细讨论)。 这里不需要调用某个特定的方法(比如<literal>update""()</literal>,设计它的目的是不同的)将你的修改持久化。 所以最直接的更新一个对""象的方法就是在<literal>Session</literal>处于打开状态时<literal>load()</""literal>它,然后直接修改即可:"#. Tag: programlisting#: session_api.xml:520#, no-c-formatmsgid """<![CDATA[DomesticCat cat = (DomesticCat) sess.load( Cat.class, new Long""(69) );\n""cat.setName(\"PK\");\n""sess.flush(); // changes to cat are automatically detected and persisted]]>"msgstr ""#. Tag: para#: session_api.xml:522#, no-c-formatmsgid """Sometimes this programming model is inefficient since it would require both ""an SQL <literal>SELECT</literal> (to load an object) and an SQL ""<literal>UPDATE</literal> (to persist its updated state) in the same ""session. Therefore Hibernate offers an alternate approach, using detached ""instances."msgstr """有时这种程序模型效率低下,因为它在同一Session里需要一条SQL <literal>SELECT</""literal>语句(用于加载对象) 以及一条SQL <literal>UPDATE</literal>语句(持久化""更新的状态)。 为此Hibernate提供了另一种途径,使用脱管(detached)实例。"#. Tag: emphasis#: session_api.xml:530#, fuzzy, no-c-formatmsgid """Note that Hibernate does not offer its own API for direct execution of ""<literal>UPDATE</literal> or <literal>DELETE</literal> statements. Hibernate ""is a <emphasis>state management</emphasis> service, you don't have to think ""in <emphasis>statements</emphasis> to use it. JDBC is a perfect API for ""executing SQL statements, you can get a JDBC <literal>Connection</literal> ""at any time by calling <literal>session.connection()</literal>. Furthermore, ""the notion of mass operations conflicts with object/relational mapping for ""online transaction processing-oriented applications. Future versions of ""Hibernate may however provide special mass operation functions. See <xref ""linkend=\"batch\"/> for some possible batch operation tricks."msgstr """请注意Hibernate本身不提供直接执行<placeholder-1/>或<placeholder-2/>语句的""API。 Hibernate提供的是<placeholder-3/>服务,你不必考虑要使用的<placeholder-""4/>。 JDBC是出色的执行SQL语句的API,任何时候调用<placeholder-5/>你都可以得到""一个JDBC <placeholder-6/>对象。 此外,在联机事务处理(OLTP)程序中,大量操作""(mass operations)与对象/关系映射的观点是相冲突的。 Hibernate的将来版本可能会""提供专门的进行大量操作(mass operation)的功能。 参考<xref linkend=\"batch\"/"">,寻找一些可用的批量(batch)操作技巧。"#. Tag: title#: session_api.xml:545#, no-c-formatmsgid "Modifying detached objects"msgstr "修改脱管(Detached)对象"#. Tag: para#: session_api.xml:547#, no-c-formatmsgid """Many applications need to retrieve an object in one transaction, send it to ""the UI layer for manipulation, then save the changes in a new transaction. ""Applications that use this kind of approach in a high-concurrency ""environment usually use versioned data to ensure isolation for the \"long\" ""unit of work."msgstr """很多程序需要在某个事务中获取对象,然后将对象发送到界面层去操作,最后在一个新""的事务保存所做的修改。 在高并发访问的环境中使用这种方式,通常使用附带版本信息""的数据来保证这些“长“工作单元之间的隔离。"#. Tag: para#: session_api.xml:554#, no-c-formatmsgid """Hibernate supports this model by providing for reattachment of detached ""instances using the <literal>Session.update()</literal> or <literal>Session.""merge()</literal> methods:"msgstr """Hibernate通过提供<literal>Session.update()</literal>或<literal>Session.merge""()</literal> 重新关联脱管实例的办法来支持这种模型。"#. Tag: programlisting#: session_api.xml:560#, no-c-formatmsgid """<![CDATA[// in the first session\n""Cat cat = (Cat) firstSession.load(Cat.class, catId);\n""Cat potentialMate = new Cat();\n""firstSession.save(potentialMate);\n""\n""// in a higher layer of the application\n""cat.setMate(potentialMate);\n""\n""// later, in a new session\n""secondSession.update(cat); // update cat\n""secondSession.update(mate); // update mate]]>"msgstr ""#. Tag: para#: session_api.xml:562#, no-c-formatmsgid """If the <literal>Cat</literal> with identifier <literal>catId</literal> had ""already been loaded by <literal>secondSession</literal> when the application ""tried to reattach it, an exception would have been thrown."msgstr """如果具有<literal>catId</literal>持久化标识的<literal>Cat</literal>之前已经被""<literal>另一Session(secondSession)</literal>装载了, 应用程序进行重关联操作""(reattach)的时候会抛出一个异常。"#. Tag: para#: session_api.xml:568#, no-c-formatmsgid """Use <literal>update()</literal> if you are sure that the session does not ""contain an already persistent instance with the same identifier, and ""<literal>merge()</literal> if you want to merge your modifications at any ""time without consideration of the state of the session. In other words, ""<literal>update()</literal> is usually the first method you would call in a ""fresh session, ensuring that reattachment of your detached instances is the ""first operation that is executed."msgstr """如果你确定当前session没有包含与之具有相同持久化标识的持久实例,使用""<literal>update()</literal>。 如果想随时合并你的的改动而不考虑session的状态,""使用<literal>merge()</literal>。 换句话说,在一个新session中通常第一个调用的""是<literal>update()</literal>方法,以便保证重新关联脱管(detached)对象的操作首""先被执行。"#. Tag: para#: session_api.xml:577#, no-c-formatmsgid """The application should individually <literal>update()</literal> detached ""instances reachable from the given detached instance if and <emphasis>only</""emphasis> if it wants their state also updated. This can be automated of ""course, using <emphasis>transitive persistence</emphasis>, see <xref linkend=""\"objectstate-transitive\"/>."msgstr """如果希望相关联的脱管对象(通过引用“可到达”的脱管对象)的数据也要更新到数据库""时(并且也<emphasis>仅仅</emphasis>在这种情况), 可以对该相关联的脱管对象单""独调用<literal>update()</literal> 当然这些可以自动完成,即通过使用<emphasis>""传播性持久化(transitive persistence)</emphasis>,请看<xref linkend=""\"objectstate-transitive\"/>。"#. Tag: para#: session_api.xml:584#, no-c-formatmsgid """The <literal>lock()</literal> method also allows an application to ""reassociate an object with a new session. However, the detached instance has ""to be unmodified!"msgstr """<literal>lock()</literal>方法也允许程序重新关联某个对象到一个新session上。不""过,该脱管(detached)的对象必须是没有修改过的!"#. Tag: programlisting#: session_api.xml:589#, no-c-formatmsgid """<![CDATA[//just reassociate:\n""sess.lock(fritz, LockMode.NONE);\n""//do a version check, then reassociate:\n""sess.lock(izi, LockMode.READ);\n""//do a version check, using SELECT ... FOR UPDATE, then reassociate:\n""sess.lock(pk, LockMode.UPGRADE);]]>"msgstr ""#. Tag: para#: session_api.xml:591#, no-c-formatmsgid """Note that <literal>lock()</literal> can be used with various ""<literal>LockMode</literal>s, see the API documentation and the chapter on ""transaction handling for more information. Reattachment is not the only ""usecase for <literal>lock()</literal>."msgstr """请注意,<literal>lock()</literal>可以搭配多种<literal>LockMode</literal>, 更""多信息请阅读API文档以及关于事务处理(transaction handling)的章节。重新关联不是""<literal>lock()</literal>的唯一用途。"#. Tag: para#: session_api.xml:598#, no-c-formatmsgid """Other models for long units of work are discussed in <xref linkend=""\"transactions-optimistic\"/>."msgstr """其他用于长时间工作单元的模型会在<xref linkend=\"transactions-optimistic\"/>中""讨论。"#. Tag: title#: session_api.xml:605#, no-c-formatmsgid "Automatic state detection"msgstr "自动状态检测"#. Tag: para#: session_api.xml:607#, no-c-formatmsgid """Hibernate users have requested a general purpose method that either saves a ""transient instance by generating a new identifier or updates/reattaches the ""detached instances associated with its current identifier. The ""<literal>saveOrUpdate()</literal> method implements this functionality."msgstr """Hibernate的用户曾要求一个既可自动分配新持久化标识(identifier)保存瞬时""(transient)对象,又可更新/重新关联脱管(detached)实例的通用方法。 ""<literal>saveOrUpdate()</literal>方法实现了这个功能。"#. Tag: programlisting#: session_api.xml:614#, no-c-formatmsgid """<![CDATA[// in the first session\n""Cat cat = (Cat) firstSession.load(Cat.class, catID);\n""\n""// in a higher tier of the application\n""Cat mate = new Cat();\n""cat.setMate(mate);\n""\n""// later, in a new session\n""secondSession.saveOrUpdate(cat); // update existing state (cat has a non-""null id)\n""secondSession.saveOrUpdate(mate); // save the new instance (mate has a null ""id)]]>"msgstr ""#. Tag: para#: session_api.xml:616#, no-c-formatmsgid """The usage and semantics of <literal>saveOrUpdate()</literal> seems to be ""confusing for new users. Firstly, so long as you are not trying to use ""instances from one session in another new session, you should not need to ""use <literal>update()</literal>, <literal>saveOrUpdate()</literal>, or ""<literal>merge()</literal>. Some whole applications will never use either of ""these methods."msgstr """<literal>saveOrUpdate()</literal>用途和语义可能会使新用户感到迷惑。 首先,只""要你没有尝试在某个session中使用来自另一session的实例,你就应该不需要使用""<literal>update()</literal>, <literal>saveOrUpdate()</literal>,或""<literal>merge()</literal>。有些程序从来不用这些方法。"#. Tag: para#: session_api.xml:624#, no-c-formatmsgid """Usually <literal>update()</literal> or <literal>saveOrUpdate()</literal> are ""used in the following scenario:"msgstr """通常下面的场景会使用<literal>update()</literal>或<literal>saveOrUpdate()</""literal>:"#. Tag: para#: session_api.xml:631#, no-c-formatmsgid "the application loads an object in the first session"msgstr "程序在第一个session中加载对象"#. Tag: para#: session_api.xml:636#, no-c-formatmsgid "the object is passed up to the UI tier"msgstr "该对象被传递到表现层"#. Tag: para#: session_api.xml:641#, no-c-formatmsgid "some modifications are made to the object"msgstr "对象发生了一些改动"#. Tag: para#: session_api.xml:646#, no-c-formatmsgid "the object is passed back down to the business logic tier"msgstr "该对象被返回到业务逻辑层"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -