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

📄 session_api.pot

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 POT
📖 第 1 页 / 共 3 页
字号:
msgstr ""#: session_api.xml:508(para) msgid "Note that the actual program code is independent of the query language that is used, you may also define native SQL queries in metadata, or migrate existing queries to Hibernate by placing them in mapping files."msgstr ""#: session_api.xml:514(para) msgid "Also note that a query declaration inside a <literal>&lt;hibernate-mapping&gt;</literal> element requires a global unique name for the query, while a query declaration inside a <literal>&lt;class&gt;</literal> element is made unique automatically by prepending the fully qualified name of the class, for example <literal>eg.Cat.ByNameAndMaximumWeight</literal>."msgstr ""#: session_api.xml:527(title) msgid "Filtering collections"msgstr ""#: session_api.xml:528(para) msgid "A collection <emphasis>filter</emphasis> is a special type of query that may be applied to a persistent collection or array. The query string may refer to <literal>this</literal>, meaning the current collection element."msgstr ""#: session_api.xml:541(para) msgid "The returned collection is considered a bag, and it's a copy of the given collection. The original collection is not modified (this is contrary to the implication of the name \"filter\", but consistent with expected behavior)."msgstr ""#: session_api.xml:547(para) msgid "Observe that filters do not require a <literal>from</literal> clause (though they may have one if required). Filters are not limited to returning the collection elements themselves."msgstr ""#: session_api.xml:557(para) msgid "Even an empty filter query is useful, e.g. to load a subset of elements in a huge collection:"msgstr ""#: session_api.xml:570(title) msgid "Criteria queries"msgstr ""#: session_api.xml:572(para) msgid "HQL is extremely powerful but some developers prefer to build queries dynamically, using an object-oriented API, rather than building query strings. Hibernate provides an intuitive <literal>Criteria</literal> query API for these cases:"msgstr ""#: session_api.xml:583(para) msgid "The <literal>Criteria</literal> and the associated <literal>Example</literal> API are discussed in more detail in <xref linkend=\"querycriteria\"/>."msgstr ""#: session_api.xml:591(title) msgid "Queries in native SQL"msgstr ""#: session_api.xml:593(para) msgid "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 ""#: session_api.xml:612(para) msgid "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 ""#: session_api.xml:623(title) msgid "Modifying persistent objects"msgstr ""#: session_api.xml:625(para) msgid "<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 ""#: session_api.xml:640(para) msgid "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_api.xml:649(literal) msgid "UPDATE"msgstr ""#: session_api.xml:649(literal) msgid "DELETE"msgstr ""#: session_api.xml:650(emphasis) msgid "state management"msgstr ""#: session_api.xml:651(emphasis) msgid "statements"msgstr ""#: session_api.xml:652(literal) msgid "Connection"msgstr ""#: session_api.xml:653(literal) msgid "session.connection()"msgstr ""#: session_api.xml:648(emphasis) msgid "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."msgstr ""#: session_api.xml:663(title) msgid "Modifying detached objects"msgstr ""#: session_api.xml:665(para) msgid "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 ""#: session_api.xml:672(para) msgid "Hibernate supports this model by providing for reattachment of detached instances using the <literal>Session.update()</literal> or <literal>Session.merge()</literal> methods:"msgstr ""#: session_api.xml:690(para) msgid "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 ""#: session_api.xml:696(para) msgid "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_api.xml:705(para) msgid "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 ""#: session_api.xml:712(para) msgid "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 ""#: session_api.xml:724(para) msgid "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 ""#: session_api.xml:731(para) msgid "Other models for long units of work are discussed in <xref linkend=\"transactions-optimistic\"/>."msgstr ""#: session_api.xml:738(title) msgid "Automatic state detection"msgstr ""#: session_api.xml:740(para) msgid "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 ""#: session_api.xml:758(para) msgid "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 ""#: session_api.xml:766(para) msgid "Usually <literal>update()</literal> or <literal>saveOrUpdate()</literal> are used in the following scenario:"msgstr ""#: session_api.xml:773(para) msgid "the application loads an object in the first session"msgstr ""#: session_api.xml:778(para) msgid "the object is passed up to the UI tier"msgstr ""#: session_api.xml:783(para) msgid "some modifications are made to the object"msgstr ""#: session_api.xml:788(para) msgid "the object is passed back down to the business logic tier"msgstr ""#: session_api.xml:793(para) msgid "the application persists these modifications by calling <literal>update()</literal> in a second session"msgstr ""#: session_api.xml:800(para) msgid "<literal>saveOrUpdate()</literal> does the following:"msgstr ""#: session_api.xml:806(para) msgid "if the object is already persistent in this session, do nothing"msgstr ""#: session_api.xml:811(para) msgid "if another object associated with the session has the same identifier, throw an exception"msgstr ""#: session_api.xml:817(para) msgid "if the object has no identifier property, <literal>save()</literal> it"msgstr ""#: session_api.xml:822(para) msgid "if the object's identifier has the value assigned to a newly instantiated object, <literal>save()</literal> it"msgstr ""#: session_api.xml:828(para) msgid "if the object is versioned (by a <literal>&lt;version&gt;</literal> or <literal>&lt;timestamp&gt;</literal>), and the version property value is the same value assigned to a newly instantiated object, <literal>save()</literal> it"msgstr ""#: session_api.xml:836(para) msgid "otherwise <literal>update()</literal> the object"msgstr ""#: session_api.xml:842(para) msgid "and <literal>merge()</literal> is very different:"msgstr ""#: session_api.xml:848(para) msgid "if there is a persistent instance with the same identifier currently associated with the session, copy the state of the given object onto the persistent instance"msgstr ""#: session_api.xml:855(para) msgid "if there is no persistent instance currently associated with the session, try to load it from the database, or create a new persistent instance"msgstr ""#: session_api.xml:861(para) msgid "the persistent instance is returned"msgstr ""#: session_api.xml:866(para) msgid "the given instance does not become associated with the session, it remains detached"msgstr ""

⌨️ 快捷键说明

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