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

📄 session_api.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 5 页
字号:
">."#. Tag: title#: session_api.xml:458#, no-c-formatmsgid "Queries in native SQL"msgstr "Queries in native SQL"#. Tag: para#: session_api.xml:460#, no-c-formatmsgid """You may express a query in SQL, using <literal>createSQLQuery()</literal> ""and let Hibernate take care of the mapping from result sets to objects. Note ""that you may at any time call <literal>session.connection()</literal> and ""use the JDBC <literal>Connection</literal> directly. If you chose to use the ""Hibernate API, you must enclose SQL aliases in braces:"msgstr """You may express a query in SQL, using <literal>createSQLQuery()</literal> ""and let Hibernate take care of the mapping from result sets to objects. Note ""that you may at any time call <literal>session.connection()</literal> and ""use the JDBC <literal>Connection</literal> directly. If you chose to use the ""Hibernate API, you must enclose SQL aliases in braces:"#. Tag: programlisting#: session_api.xml:468#, 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:470#, 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:472#, 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 """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\"/>."#. Tag: title#: session_api.xml:483#, no-c-formatmsgid "Modifying persistent objects"msgstr "Modifying persistent objects"#. Tag: para#: session_api.xml:485#, 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>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:"#. Tag: programlisting#: session_api.xml:496#, 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:498#, 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 """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."#. Tag: emphasis#: session_api.xml:506#, 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 """Note that Hibernate does not offer its own API for direct execution of ""<placeholder-1/> or <placeholder-2/> statements. Hibernate is a <placeholder-""3/> service, you don't have to think in <placeholder-4/> to use it. JDBC is ""a perfect API for executing SQL statements, you can get a JDBC <placeholder-""5/> at any time by calling <placeholder-6/>. 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."#. Tag: title#: session_api.xml:521#, no-c-formatmsgid "Modifying detached objects"msgstr "Modifying detached objects"#. Tag: para#: session_api.xml:523#, 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 """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."#. Tag: para#: session_api.xml:530#, 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 supports this model by providing for reattachment of detached ""instances using the <literal>Session.update()</literal> or <literal>Session.""merge()</literal> methods:"#. Tag: programlisting#: session_api.xml:536#, 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:538#, 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 """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."#. Tag: para#: session_api.xml:544#, 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 """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."#. Tag: para#: session_api.xml:553#, 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 """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\"/>."#. Tag: para#: session_api.xml:560#, 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 """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!"#. Tag: programlisting#: session_api.xml:565#, 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:567#, 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 """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>."#. Tag: para#: session_api.xml:574#, no-c-formatmsgid """Other models for long units of work are discussed in <xref linkend=""\"transactions-optimistic\"/>."msgstr """Other models for long units of work are discussed in <xref linkend=""\"transactions-optimistic\"/>."#. Tag: title#: session_api.xml:581#, no-c-formatmsgid "Automatic state detection"msgstr "Automatic state detection"#. Tag: para#: session_api.xml:583#, 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 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."#. Tag: programlisting#: session_api.xml:590#, 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:592#, 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 """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."#. Tag: para#: session_api.xml:600#, no-c-formatmsgid """Usually <literal>update()</literal> or <literal>saveOrUpdate()</literal> are ""used in the following scenario:"msgstr """Usually <literal>update()</literal> or <literal>saveOrUpdate()</literal> are ""used in the following scenario:"

⌨️ 快捷键说明

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