📄 session_api.pot
字号:
msgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""POT-Creation-Date: 2007-10-19 10:34-0500\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <LL@li.org>\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"#: session_api.xml:5(title) msgid "Working with objects"msgstr ""#: session_api.xml:7(para) msgid "Hibernate is a full object/relational mapping solution that not only shields the developer from the details of the underlying database management system, but also offers <emphasis>state management</emphasis> of objects. This is, contrary to the management of SQL <literal>statements</literal> in common JDBC/SQL persistence layers, a very natural object-oriented view of persistence in Java applications."msgstr ""#: session_api.xml:16(para) msgid "In other words, Hibernate application developers should always think about the <emphasis>state</emphasis> of their objects, and not necessarily about the execution of SQL statements. This part is taken care of by Hibernate and is only relevant for the application developer when tuning the performance of the system."msgstr ""#: session_api.xml:24(title) msgid "Hibernate object states"msgstr ""#: session_api.xml:26(para) msgid "Hibernate defines and supports the following object states:"msgstr ""#: session_api.xml:32(para) msgid "<emphasis>Transient</emphasis> - an object is transient if it has just been instantiated using the <literal>new</literal> operator, and it is not associated with a Hibernate <literal>Session</literal>. It has no persistent representation in the database and no identifier value has been assigned. Transient instances will be destroyed by the garbage collector if the application doesn't hold a reference anymore. Use the Hibernate <literal>Session</literal> to make an object persistent (and let Hibernate take care of the SQL statements that need to be executed for this transition)."msgstr ""#: session_api.xml:44(para) msgid "<emphasis>Persistent</emphasis> - a persistent instance has a representation in the database and an identifier value. It might just have been saved or loaded, however, it is by definition in the scope of a <literal>Session</literal>. Hibernate will detect any changes made to an object in persistent state and synchronize the state with the database when the unit of work completes. Developers don't execute manual <literal>UPDATE</literal> statements, or <literal>DELETE</literal> statements when an object should be made transient."msgstr ""#: session_api.xml:55(para) msgid "<emphasis>Detached</emphasis> - a detached instance is an object that has been persistent, but its <literal>Session</literal> has been closed. The reference to the object is still valid, of course, and the detached instance might even be modified in this state. A detached instance can be reattached to a new <literal>Session</literal> at a later point in time, making it (and all the modifications) persistent again. This feature enables a programming model for long running units of work that require user think-time. We call them <emphasis>application transactions</emphasis>, i.e. a unit of work from the point of view of the user."msgstr ""#: session_api.xml:69(para) msgid "We'll now discuss the states and state transitions (and the Hibernate methods that trigger a transition) in more detail."msgstr ""#: session_api.xml:77(title) msgid "Making objects persistent"msgstr ""#: session_api.xml:79(para) msgid "Newly instantiated instances of a a persistent class are considered <emphasis>transient</emphasis> by Hibernate. We can make a transient instance <emphasis>persistent</emphasis> by associating it with a session:"msgstr ""#: session_api.xml:92(para) msgid "If <literal>Cat</literal> has a generated identifier, the identifier is generated and assigned to the <literal>cat</literal> when <literal>save()</literal> is called. If <literal>Cat</literal> has an <literal>assigned</literal> identifier, or a composite key, the identifier should be assigned to the <literal>cat</literal> instance before calling <literal>save()</literal>. You may also use <literal>persist()</literal> instead of <literal>save()</literal>, with the semantics defined in the EJB3 early draft."msgstr ""#: session_api.xml:104(para) msgid "<literal>persist()</literal> makes a transient instance persistent. However, it doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time. <literal>persist()</literal> also guarantees that it will not execute an <literal>INSERT</literal> statement if it is called outside of transaction boundaries. This is useful in long-running conversations with an extended Session/persistence context."msgstr ""#: session_api.xml:115(para) msgid "<literal>save()</literal> does guarantee to return an identifier. If an INSERT has to be executed to get the identifier ( e.g. \"identity\" generator, not \"sequence\"), this INSERT happens immediately, no matter if you are inside or outside of a transaction. This is problematic in a long-running conversation with an extended Session/persistence context."msgstr ""#: session_api.xml:125(para) msgid "Alternatively, you may assign the identifier using an overloaded version of <literal>save()</literal>."msgstr ""#: session_api.xml:138(para) msgid "If the object you make persistent has associated objects (e.g. the <literal>kittens</literal> collection in the previous example), these objects may be made persistent in any order you like unless you have a <literal>NOT NULL</literal> constraint upon a foreign key column. There is never a risk of violating foreign key constraints. However, you might violate a <literal>NOT NULL</literal> constraint if you <literal>save()</literal> the objects in the wrong order."msgstr ""#: session_api.xml:148(para) msgid "Usually you don't bother with this detail, as you'll very likely use Hibernate's <emphasis>transitive persistence</emphasis> feature to save the associated objects automatically. Then, even <literal>NOT NULL</literal> constraint violations don't occur - Hibernate will take care of everything. Transitive persistence is discussed later in this chapter."msgstr ""#: session_api.xml:159(title) msgid "Loading an object"msgstr ""#: session_api.xml:161(para) msgid "The <literal>load()</literal> methods of <literal>Session</literal> gives you a way to retrieve a persistent instance if you already know its identifier. <literal>load()</literal> takes a class object and will load the state into a newly instantiated instance of that class, in persistent state."msgstr ""#: session_api.xml:174(para) msgid "Alternatively, you can load state into a given instance:"msgstr ""#: session_api.xml:183(para) msgid "Note that <literal>load()</literal> will throw an unrecoverable exception if there is no matching database row. If the class is mapped with a proxy, <literal>load()</literal> just returns an uninitialized proxy and does not actually hit the database until you invoke a method of the proxy. This behaviour is very useful if you wish to create an association to an object without actually loading it from the database. It also allows multiple instances to be loaded as a batch if <literal>batch-size</literal> is defined for the class mapping."msgstr ""#: session_api.xml:194(para) msgid "If you are not certain that a matching row exists, you should use the <literal>get()</literal> method, which hits the database immediately and returns null if there is no matching row."msgstr ""#: session_api.xml:207(para) msgid "You may even load an object using an SQL <literal>SELECT ... FOR UPDATE</literal>, using a <literal>LockMode</literal>. See the API documentation for more information."msgstr ""#: session_api.xml:214(para) msgid "Note that any associated instances or contained collections are <emphasis>not</emphasis> selected <literal>FOR UPDATE</literal>, unless you decide to specify <literal>lock</literal> or <literal>all</literal> as a cascade style for the association."msgstr ""#: session_api.xml:221(para) msgid "It is possible to re-load an object and all its collections at any time, using the <literal>refresh()</literal> method. This is useful when database triggers are used to initialize some of the properties of the object."msgstr ""#: session_api.xml:231(para) msgid "An important question usually appears at this point: How much does Hibernate load from the database and how many SQL <literal>SELECT</literal>s will it use? This depends on the <emphasis>fetching strategy</emphasis> and is explained in <xref linkend=\"performance-fetching\"/>."msgstr ""#: session_api.xml:241(title) msgid "Querying"msgstr ""#: session_api.xml:243(para) msgid "If you don't know the identifiers of the objects you are looking for, you need a query. Hibernate supports an easy-to-use but powerful object oriented query language (HQL). For programmatic query creation, Hibernate supports a sophisticated Criteria and Example query feature (QBC and QBE). You may also express your query in the native SQL of your database, with optional support from Hibernate for result set conversion into objects."msgstr ""#: session_api.xml:253(title) msgid "Executing queries"msgstr ""#: session_api.xml:255(para) msgid "HQL and native SQL queries are represented with an instance of <literal>org.hibernate.Query</literal>. This interface offers methods for parameter binding, result set handling, and for the execution of the actual query. You always obtain a <literal>Query</literal> using the current <literal>Session</literal>:"msgstr ""#: session_api.xml:286(para) msgid "A query is usually executed by invoking <literal>list()</literal>, the result of the query will be loaded completely into a collection in memory. Entity instances retrieved by a query are in persistent state. The <literal>uniqueResult()</literal> method offers a shortcut if you know your query will only return a single object. Note that queries that make use of eager fetching of collections usually return duplicates of the root objects (but with their collections initialized). You can filter these duplicates simply through a <literal>Set</literal>."msgstr ""#: session_api.xml:298(title) msgid "Iterating results"msgstr ""#: session_api.xml:300(para) msgid "Occasionally, you might be able to achieve better performance by executing the query using the <literal>iterate()</literal> method. This will only usually be the case if you expect that the actual entity instances returned by the query will already be in the session or second-level cache. If they are not already cached, <literal>iterate()</literal> will be slower than <literal>list()</literal> and might require many database hits for a simple query, usually <emphasis>1</emphasis> for the initial select which only returns identifiers, and <emphasis>n</emphasis> additional selects to initialize the actual instances."msgstr ""#: session_api.xml:327(title) msgid "Queries that return tuples"msgstr ""#: session_api.xml:329(para) msgid "Hibernate queries sometimes return tuples of objects, in which case each tuple is returned as an array:"msgstr ""#: session_api.xml:349(title) msgid "Scalar results"msgstr ""#: session_api.xml:351(para) msgid "Queries may specify a property of a class in the <literal>select</literal> clause. They may even call SQL aggregate functions. Properties or aggregates are considered \"scalar\" results (and not entities in persistent state)."msgstr ""#: session_api.xml:374(title) msgid "Bind parameters"msgstr ""#: session_api.xml:376(para) msgid "Methods on <literal>Query</literal> are provided for binding values to named parameters or JDBC-style <literal>?</literal> parameters. <emphasis>Contrary to JDBC, Hibernate numbers parameters from zero.</emphasis> Named parameters are identifiers of the form <literal>:name</literal> in the query string. The advantages of named parameters are:"msgstr ""#: session_api.xml:386(para) msgid "named parameters are insensitive to the order they occur in the query string"msgstr ""#: session_api.xml:392(para) msgid "they may occur multiple times in the same query"msgstr ""#: session_api.xml:397(para) msgid "they are self-documenting"msgstr ""#: session_api.xml:424(title) msgid "Pagination"msgstr ""#: session_api.xml:426(para) msgid "If you need to specify bounds upon your result set (the maximum number of rows you want to retrieve and / or the first row you want to retrieve) you should use methods of the <literal>Query</literal> interface:"msgstr ""#: session_api.xml:437(para) msgid "Hibernate knows how to translate this limit query into the native SQL of your DBMS."msgstr ""#: session_api.xml:445(title) msgid "Scrollable iteration"msgstr ""#: session_api.xml:447(para) msgid "If your JDBC driver supports scrollable <literal>ResultSet</literal>s, the <literal>Query</literal> interface may be used to obtain a <literal>ScrollableResults</literal> object, which allows flexible navigation of the query results."msgstr ""#: session_api.xml:476(para) msgid "Note that an open database connection (and cursor) is required for this functionality, use <literal>setMaxResult()</literal>/<literal>setFirstResult()</literal> if you need offline pagination functionality."msgstr ""#: session_api.xml:485(title) msgid "Externalizing named queries"msgstr ""#: session_api.xml:487(para) msgid "You may also define named queries in the mapping document. (Remember to use a <literal>CDATA</literal> section if your query contains characters that could be interpreted as markup.)"msgstr ""#: session_api.xml:499(para) msgid "Parameter binding and executing is done programatically:"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -