alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (session_api.po)

This example Hibernate source code file (session_api.po) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

cat, cat, cdata, domesticcat, hibernate, hibernate, if, list, sql, sql, tag, tag, the, this

The Hibernate session_api.po source code

# translation of session_api.po to
# Xi Huang <xhuang@redhat.com>, 2006.
# Xi HUANG <xhuang@redhat.com>, 2007, 2009.
# translation of Collection_Mapping.po to
msgid ""
msgstr ""
"Project-Id-Version: session_api\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-21 05:43+0000\n"
"PO-Revision-Date: 2010-03-16 09:58+1000\n"
"Last-Translator: Xi HUANG <xhuang@redhat.com>\n"
"Language-Team:  <en@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: KBabel 1.11.4\n"

#. Tag: title
#: session_api.xml:31
#, no-c-format
msgid "Working with objects"
msgstr "与对象共事"

#. Tag: para
#: session_api.xml:33
#, no-c-format
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 of objects. This is, "
"contrary to the management of SQL <literal>statements in common "
"JDBC/SQL persistence layers, a natural object-oriented view of persistence "
"in Java applications."
msgstr ""
"Hibernate 是完整的对象/关系映射解决方案,它提供了对象<emphasis>状态管理"
"(state management)</emphasis>的功能,使开发者不再需要理会底层数据库系统的细"
"节。也就是说,相对于常见的 JDBC/SQL 持久层方案中需要<literal>管理 SQL 语句 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 ""
"换句话说,使用 Hibernate 的开发者应该总是关注对象的<emphasis>状态(state) - an object is transient if it has just been "
"instantiated using the <literal>new operator, and it is not "
"associated with a Hibernate <literal>Session. 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 does not hold a reference anymore. Use the Hibernate "
"<literal>Session to make an object persistent (and let Hibernate "
"take care of the SQL statements that need to be executed for this "
"transition)."
msgstr ""
"<emphasis>瞬时(Transient) — 由 new 操作符创"
"建,且尚未与Hibernate <literal>Session 关联的对象被认定为瞬时"
"(Transient)的。瞬时(Transient)对象不会被持久化到数据库中,也不会被赋予持"
"久化标识(identifier)。 如果瞬时(Transient)对象在程序中没有被引用,它会被"
"垃圾回收器(garbage collector)销毁。 使用 Hibernate <literal>Session - 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 "
"statements, or <literal>DELETE statements when an object should be "
"made transient."
msgstr ""
"<emphasis>持久(Persistent) — 持久(Persistent)的实例在数据库中"
"有对应的记录,并拥有一个持久化标识(identifier)。 持久(Persistent)的实例可"
"能是刚被保存的,或刚被加载的,无论哪一种,按定义,它存在于相关联的"
"<literal>Session作用范围内。 Hibernate会检测到处于持久"
"(Persistent)状态的对象的任何改动,在当前操作单元(unit of work)执行完毕时"
"将对象数据(state)与数据库同步(synchronize)。 开发者不需要手动执行"
"<literal>UPDATE。将对象从持久(Persistent)状态变成瞬时"
"(Transient)状态同样也不需要手动执行 <literal>DELETE 语句。 "

#. Tag: para
#: session_api.xml:77
#, no-c-format
msgid ""
"<emphasis>Detached - a detached instance is an object that has "
"been persistent, but its <literal>Session 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 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, i.e., a unit of work "
"from the point of view of the user."
msgstr ""
"<emphasis>脱管(Detached) — 与持久(Persistent)对象关联的"
"<literal>Session被关闭后,对象就变为脱管(Detached)的。对脱管"
"(Detached)对象的引用依然有效,对象可继续被修改。脱管(Detached)对象如果重"
"新关联到某个新的 <literal>Session 上, 会再次转变为持久"
"(Persistent)的(在Detached其间的改动将被持久化到数据库)。 这个功能使得一种"
"编程模型,即中间会给用户思考时间(user think-time)的长时间运行的操作单元"
"(unit of work)的编程模型成为可能。我们称之为<emphasis>应用程序事务 by Hibernate. We can make a transient "
"instance <emphasis>persistent by associating it with a session:"
msgstr ""
"Hibernate 认为持久化类(persistent class)新实例化的对象是<emphasis>瞬时"
"(Transient)</emphasis>的。我们可通过将瞬时(Transient)对象与 session 关联"
"而把它变为<emphasis>持久的(Persistent)。"

#. Tag: programlisting
#: session_api.xml:102
#, fuzzy, no-c-format
msgid ""
"DomesticCat fritz = new DomesticCat();\n"
"fritz.setColor(Color.GINGER);\n"
"fritz.setSex('M');\n"
"fritz.setName(\"Fritz\");\n"
"Long generatedId = (Long) sess.save(fritz);"
msgstr ""
"<![CDATA[DomesticCat fritz = new DomesticCat();\n"
"fritz.setColor(Color.GINGER);\n"
"fritz.setSex('M');\n"
"fritz.setName(\"Fritz\");\n"
"Long generatedId = (Long) sess.save(fritz);]]>"

#. Tag: para
#: session_api.xml:104
#, no-c-format
msgid ""
"If <literal>Cat has a generated identifier, the identifier is "
"generated and assigned to the <literal>cat when save()Cat has an assigned instance before calling save()persist() instead of "
"<literal>save(), with the semantics defined in the EJB3 early "
"draft."
msgstr ""
"如果 <literal>Cat 的持久化标识(identifier)是 generatedsave() "
"被调用时产生并分配给 <literal>cat。如果 Cat 的持"
"久化标识(identifier)是<literal>assigned类型的,或是一个复合主键"
"(composite key),那么该标识(identifier)应当在调用 <literal>save()cat。你也可以按照 EJB3 early "
"draft 中定义的语义,使用 <literal>persist() 替代save() makes a transient instance persistent. However, "
"it does not guarantee that the identifier value will be assigned to the "
"persistent instance immediately, the assignment might happen at flush time. "
"<literal>persist() also guarantees that it will not execute an "
"<literal>INSERT statement if it is called outside of transaction "
"boundaries. This is useful in long-running conversations with an extended "
"Session/persistence context."
msgstr ""
"<literal>persist() 使一个临时实例持久化。然而,它不保证立即把标识符"
"值分配给持久性实例,这会发生在冲刷(flush)的时候。<literal>persist()INSERT 语句。"
"这对于长期运行的带有扩展会话/持久化上下文的会话是很有用的。"

#. Tag: para
#: session_api.xml:126
#, no-c-format
msgid ""
"<literal>save() 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 ""
"<literal>save() 保证返回一个标识符。如果需要运行 INSERT 来获取标识"
"符(如 \"identity\" 而非 \"sequence\" 生成器),这个 INSERT 将立即执行,不管"
"你是否在事务内部还是外部。这对于长期运行的带有扩展会话/持久化上下文的会话来说"
"会出现问题。"

#. Tag: para
#: session_api.xml:135
#, no-c-format
msgid ""
"Alternatively, you can assign the identifier using an overloaded version of "
"<literal>save()."
msgstr "此外,你可以用一个重载版本的 <literal>save() 方法。 "

#. Tag: programlisting
#: session_api.xml:138
#, fuzzy, no-c-format
msgid ""
"DomesticCat pk = new DomesticCat();\n"
"pk.setColor(Color.TABBY);\n"
"pk.setSex('F');\n"
"pk.setName(\"PK\");\n"
"pk.setKittens( new HashSet() );\n"
"pk.addKitten(fritz);\n"
"sess.save( pk, new Long(1234) );"
msgstr ""
"<![CDATA[DomesticCat pk = new DomesticCat();\n"
"pk.setColor(Color.TABBY);\n"
"pk.setSex('F');\n"
"pk.setName(\"PK\");\n"
"pk.setKittens( new HashSet() );\n"
"pk.addKitten(fritz);\n"
"sess.save( pk, new Long(1234) );]]>"

#. Tag: para
#: session_api.xml:140
#, no-c-format
msgid ""
"If the object you make persistent has associated objects (e.g. the "
"<literal>kittens collection in the previous example), these "
"objects can be made persistent in any order you like unless you have a "
"<literal>NOT NULL constraint upon a foreign key column. There is "
"never a risk of violating foreign key constraints. However, you might "
"violate a <literal>NOT NULL constraint if you save() 集合) 那么对这些对象(译注:pk 和 kittens)进行持"
"久化的顺序是任意的(也就是说可以先对 kittens 进行持久化也可以先对 pk 进行持久"
"化), 除非你在外键列上有 <literal>NOT NULL 约束。 Hibernate 不会违"
"反外键约束,但是如果你用错误的顺序持久化对象(译注:在 pk 持久化之前持久化"
"kitten),那么可能会违反 <literal>NOT NULL 约束。 "

#. Tag: para
#: session_api.xml:148
#, no-c-format
msgid ""
"Usually you do not bother with this detail, as you will normally use "
"Hibernate's <emphasis>transitive persistence feature to save the "
"associated objects automatically. Then, even <literal>NOT NULL "
"constraint violations do not occur - Hibernate will take care of everything. "
"Transitive persistence is discussed later in this chapter."
msgstr ""
"通常你不会为这些细节烦心,因为你很可能会使用 Hibernate 的<emphasis>传播性持久"
"化(transitive persistence)</emphasis>功能自动保存相关联那些对象。这样连违"
"反 <literal>NOT NULL 约束的情况都不会出现了 — Hibernate 会管好所有"
"的事情。传播性持久化(transitive persistence)将在本章稍后讨论。"

#. Tag: title
#: session_api.xml:157
#, no-c-format
msgid "Loading an object"
msgstr "装载对象"

#. Tag: para
#: session_api.xml:159
#, no-c-format
msgid ""
"The <literal>load() methods of Session provide "
"a way of retrieving a persistent instance if you know its identifier. "
"<literal>load() takes a class object and loads the state into a "
"newly instantiated instance of that class in a persistent state."
msgstr ""
"如果你知道某个实例的持久化标识(identifier),你就可以使用 <literal>Sessionload() 方法来获取它。load() will throw an unrecoverable "
"exception if there is no matching database row. If the class is mapped with "
"a proxy, <literal>load() just returns an uninitialized proxy and "
"does not actually hit the database until you invoke a method of the proxy. "
"This is 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 is defined for the "
"class mapping."
msgstr ""
"请注意如果没有匹配的数据库记录,<literal>load() 方法可能抛出无法恢"
"复的异常(unrecoverable exception)。如果类的映射使用了代理(proxy),"
"<literal>load() 方法会返回一个未初始化的代理,直到你调用该代理的某"
"方法时才会去访问数据库。 若你希望在某对象中创建一个指向另一个对象的关联,又不"
"想在从数据库中装载该对象时同时装载相关联的那个对象,那么这种操作方式就用得上"
"的了。如果为相应类映射关系设置了 <literal>batch-size,那么使用这种"
"操作方式允许多个对象被一批装载(因为返回的是代理,无需从数据库中抓取所有对象"
"的数据)。 "

#. Tag: para
#: session_api.xml:182
#, no-c-format
msgid ""
"If you are not certain that a matching row exists, you should use the "
"<literal>get() method which hits the database immediately and "
"returns null if there is no matching row."
msgstr ""
"如果你不确定是否有匹配的行存在,应该使用 <literal>get() 方法,它会"
"立刻访问数据库,如果没有对应的记录,会返回 null。 "

#. Tag: programlisting
#: session_api.xml:186
#, fuzzy, no-c-format
msgid ""
"Cat cat = (Cat) sess.get(Cat.class, id);\n"
"if (cat==null) {\n"
"    cat = new Cat();\n"
"    sess.save(cat, id);\n"
"}\n"
"return cat;"
msgstr ""
"<![CDATA[Cat cat = (Cat) sess.get(Cat.class, id);\n"
"if (cat==null) {\n"
"    cat = new Cat();\n"
"    sess.save(cat, id);\n"
"}\n"
"return cat;]]>"

#. Tag: para
#: session_api.xml:188
#, no-c-format
msgid ""
"You can even load an object using an SQL <literal>SELECT ... FOR UPDATELockMode. See the API documentation for "
"more information."
msgstr ""
"你甚至可以选用某个 <literal>LockMode,用 SQL 的 "
"<literal>SELECT ... FOR UPDATE 装载对象。 请查阅 API 文档以获取更多"
"信息。 "

#. Tag: programlisting
#: session_api.xml:192
#, fuzzy, no-c-format
msgid "Cat cat = (Cat) sess.get(Cat.class, id, LockMode.UPGRADE);"
msgstr "<![CDATA[Cat cat = (Cat) sess.get(Cat.class, id, LockMode.UPGRADE);]]>"

#. Tag: para
#: session_api.xml:194
#, no-c-format
msgid ""
"Any associated instances or contained collections will <emphasis>notFOR UPDATE, unless you decide to "
"specify <literal>lock or all as a cascade style "
"for the association."
msgstr ""
"注意,任何关联的对象或者包含的集合都<emphasis>不会被以 "
"<literal>FOR UPDATE 方式返回, 除非你指定了 lockall 作为关联(association)的级联风格"
"(cascade style)。 "

#. Tag: para
#: session_api.xml:199
#, no-c-format
msgid ""
"It is possible to re-load an object and all its collections at any time, "
"using the <literal>refresh() method. This is useful when database "
"triggers are used to initialize some of the properties of the object."
msgstr ""
"任何时候都可以使用 <literal>refresh() 方法强迫装载对象和它的集合。"
"如果你使用数据库触发器功能来处理对象的某些属性,这个方法就很有用了。"

#. Tag: programlisting
#: session_api.xml:204
#, fuzzy, no-c-format
msgid ""
"sess.save(cat);\n"
"sess.flush(); //force the SQL INSERT\n"
"sess.refresh(cat); //re-read the state (after the trigger executes)"
msgstr ""
"<![CDATA[sess.save(cat);\n"
"sess.flush(); //force the SQL INSERT\n"
"sess.refresh(cat); //re-read the state (after the trigger executes)]]>"

#. Tag: para
#: session_api.xml:206
#, fuzzy, no-c-format
msgid ""
"How much does Hibernate load from the database and how many SQL "
"<literal>SELECTs will it use? This depends on the "
"<emphasis>fetching strategy. This is explained in  语句?这取决于抓取策略"
"(fetching strategy)</emphasis>,我们会在  using the current Session 获取一个 Query. The "
"result of the query will be loaded completely into a collection in memory. "
"Entity instances retrieved by a query are in a persistent state. The "
"<literal>uniqueResult() method offers a shortcut if you know your "
"query will only return a single object. 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 through "
"a <literal>Set."
msgstr ""
"一个查询通常在调用 <literal>list() 时被执行,执行结果会完全装载进内"
"存中的一个集合(collection)。查询返回的对象处于持久(persistent)状态。如果"
"你知道的查询只会返回一个对象,可使用 <literal>list() 的快捷方式 "
"<literal>uniqueResult()。注意,使用集合预先抓取的查询往往会返回多次"
"根对象(他们的集合类都被初始化了)。你可以通过一个<literal>集合(Set) method. This will 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() will be slower than "
"<literal>list() and might require many database hits for a simple "
"query, usually <emphasis>1 for the initial select which only "
"returns identifiers, and <emphasis>n additional selects to "
"initialize the actual instances."
msgstr ""
"某些情况下,你可以使用 <literal>iterate() 方法得到更好的性能。 这通"
"常是你预期返回的结果在 session,或二级缓存(second-level cache)中已经存在时"
"的情况。如若不然,<literal>iterate() 会比 list()iterate()1 条语句得到所有对象的持久化标识"
"(identifiers),再根据持久化标识执行 <emphasis>n 条附加的 select "
"语句实例化实际的对象。 "

#. Tag: programlisting
#: session_api.xml:257
#, fuzzy, no-c-format
msgid ""
"// fetch ids\n"
"Iterator iter = sess.createQuery(\"from eg.Qux q order by q.likeliness\")."
"iterate();\n"
"while ( iter.hasNext() ) {\n"
"    Qux qux = (Qux) iter.next();  // fetch the object\n"
"    // something we couldnt express in the query\n"
"    if ( qux.calculateComplicatedAlgorithm() ) {\n"
"        // delete the current instance\n"
"        iter.remove();\n"
"        // dont need to process the rest\n"
"        break;\n"
"    }\n"
"}"
msgstr ""
"<![CDATA[// fetch ids\n"
"Iterator iter = sess.createQuery(\"from eg.Qux q order by q.likeliness\")."
"iterate();\n"
"while ( iter.hasNext() ) {\n"
"    Qux qux = (Qux) iter.next();  // fetch the object\n"
"    // something we couldnt express in the query\n"
"    if ( qux.calculateComplicatedAlgorithm() ) {\n"
"        // delete the current instance\n"
"        iter.remove();\n"
"        // dont need to process the rest\n"
"        break;\n"
"    }\n"
"}]]>"

#. Tag: title
#: session_api.xml:261
#, no-c-format
msgid "Queries that return tuples"
msgstr "返回元组(tuples)的查询"

#. Tag: para
#: session_api.xml:263
#, no-c-format
msgid ""
"Hibernate queries sometimes return tuples of objects. Each tuple is returned "
"as an array:"
msgstr ""
"(译注:元组(tuples)指一条结果行包含多个对象) Hibernate 查询有时返回元组"
"(tuples),每个元组(tuples)以数组的形式返回: "

#. Tag: programlisting
#: session_api.xml:266
#, fuzzy, no-c-format
msgid ""
"Iterator kittensAndMothers = sess.createQuery(\n"
"            \"select kitten, mother from Cat kitten join kitten.mother mother"
"\")\n"
"            .list()\n"
"            .iterator();\n"
"\n"
"while ( kittensAndMothers.hasNext() ) {\n"
"    Object[] tuple = (Object[]) kittensAndMothers.next();\n"
"    Cat kitten = (Cat) tuple[0];\n"
"    Cat mother = (Cat) tuple[1];\n"
"    ....\n"
"}"
msgstr ""
"<![CDATA[Iterator kittensAndMothers = sess.createQuery(\n"
"            \"select kitten, mother from Cat kitten join kitten.mother mother"
"\")\n"
"            .list()\n"
"            .iterator();\n"
"\n"
"while ( kittensAndMothers.hasNext() ) {\n"
"    Object[] tuple = (Object[]) kittensAndMothers.next();\n"
"    Cat kitten = (Cat) tuple[0];\n"
"    Cat mother = (Cat) tuple[1];\n"
"    ....\n"
"}]]>"

#. Tag: title
#: session_api.xml:270
#, no-c-format
msgid "Scalar results"
msgstr "标量(Scalar)结果"

#. Tag: para
#: session_api.xml:272
#, no-c-format
msgid ""
"Queries can specify a property of a class in the <literal>select "
"clause. They can even call SQL aggregate functions. Properties or aggregates "
"are considered \"scalar\" results and not entities in persistent state."
msgstr ""
"查询可在 <literal>select 从句中指定类的属性,甚至可以调用 SQL 统计"
"(aggregate)函数。属性或统计结果被认定为\"标量(Scalar)\"的结果(而不是持久"
"(persistent state)的实体)。 "

#. Tag: programlisting
#: session_api.xml:277
#, fuzzy, no-c-format
msgid ""
"Iterator results = sess.createQuery(\n"
"        \"select cat.color, min(cat.birthdate), count(cat) from Cat cat \" "
"+\n"
"        \"group by cat.color\")\n"
"        .list()\n"
"        .iterator();\n"
"\n"
"while ( results.hasNext() ) {\n"
"    Object[] row = (Object[]) results.next();\n"
"    Color type = (Color) row[0];\n"
"    Date oldest = (Date) row[1];\n"
"    Integer count = (Integer) row[2];\n"
"    .....\n"
"}"
msgstr ""
"<![CDATA[Iterator results = sess.createQuery(\n"
"        \"select cat.color, min(cat.birthdate), count(cat) from Cat cat \" "
"+\n"
"        \"group by cat.color\")\n"
"        .list()\n"
"        .iterator();\n"
"\n"
"while ( results.hasNext() ) {\n"
"    Object[] row = (Object[]) results.next();\n"
"    Color type = (Color) row[0];\n"
"    Date oldest = (Date) row[1];\n"
"    Integer count = (Integer) row[2];\n"
"    .....\n"
"}]]>"

#. Tag: title
#: session_api.xml:281
#, no-c-format
msgid "Bind parameters"
msgstr "绑定参数"

#. Tag: para
#: session_api.xml:283
#, no-c-format
msgid ""
"Methods on <literal>Query are provided for binding values to named "
"parameters or JDBC-style <literal>? parameters. Contrary "
"to JDBC, Hibernate numbers parameters from zero.</emphasis> Named parameters "
"are identifiers of the form <literal>:name in the query string. "
"The advantages of named parameters are as follows:"
msgstr ""
"接口 <literal>Query 提供了对命名参数(named parameters)、JDBC 风格"
"的<literal>问号(?)参数进行绑定的方法。不同于 JDBC,"
"Hibernate 对参数从 0 开始计数。</emphasis> 命名参数(named parameters)在查询"
"字符串中是形如 <literal>:name 的标识符。命名参数(named "
"parameters)的优点是: "

#. Tag: para
#: session_api.xml:292
#, no-c-format
msgid ""
"named parameters are insensitive to the order they occur in the query string"
msgstr "命名参数(named parameters)与其在查询串中出现的顺序无关"

#. Tag: para
#: session_api.xml:297
#, no-c-format
msgid "they can occur multiple times in the same query"
msgstr "它们可在同一查询串中多次出现 "

#. Tag: para
#: session_api.xml:301
#, no-c-format
msgid "they are self-documenting"
msgstr "它们本身是自我说明的"

#. Tag: programlisting
#: session_api.xml:305
#, fuzzy, no-c-format
msgid ""
"//named parameter (preferred)\n"
"Query q = sess.createQuery(\"from DomesticCat cat where cat.name = :name"
"\");\n"
"q.setString(\"name\", \"Fritz\");\n"
"Iterator cats = q.iterate();"
msgstr ""
"<![CDATA[//named parameter (preferred)\n"
"Query q = sess.createQuery(\"from DomesticCat cat where cat.name = :name"
"\");\n"
"q.setString(\"name\", \"Fritz\");\n"
"Iterator cats = q.iterate();]]>"

#. Tag: programlisting
#: session_api.xml:307
#, fuzzy, no-c-format
msgid ""
"//positional parameter\n"
"Query q = sess.createQuery(\"from DomesticCat cat where cat.name = ?\");\n"
"q.setString(0, \"Izi\");\n"
"Iterator cats = q.iterate();"
msgstr ""
"<![CDATA[//positional parameter\n"
"Query q = sess.createQuery(\"from DomesticCat cat where cat.name = ?\");\n"
"q.setString(0, \"Izi\");\n"
"Iterator cats = q.iterate();]]>"

#. Tag: programlisting
#: session_api.xml:309
#, fuzzy, no-c-format
msgid ""
"//named parameter list\n"
"List names = new ArrayList();\n"
"names.add(\"Izi\");\n"
"names.add(\"Fritz\");\n"
"Query q = sess.createQuery(\"from DomesticCat cat where cat.name in (:"
"namesList)\");\n"
"q.setParameterList(\"namesList\", names);\n"
"List cats = q.list();"
msgstr ""
"<![CDATA[//named parameter list\n"
"List names = new ArrayList();\n"
"names.add(\"Izi\");\n"
"names.add(\"Fritz\");\n"
"Query q = sess.createQuery(\"from DomesticCat cat where cat.name in (:"
"namesList)\");\n"
"q.setParameterList(\"namesList\", names);\n"
"List cats = q.list();]]>"

#. Tag: title
#: session_api.xml:313
#, no-c-format
msgid "Pagination"
msgstr "分页"

#. Tag: para
#: session_api.xml:315
#, no-c-format
msgid ""
"If you need to specify bounds upon your result set, that is, the maximum "
"number of rows you want to retrieve and/or the first row you want to "
"retrieve, you can use methods of the <literal>Query interface:"
msgstr ""
"如果你需要指定结果集的范围(希望返回的最大行数/或开始的行数),应该使用 "
"<literal>Query 接口提供的方法: "

#. Tag: programlisting
#: session_api.xml:320
#, fuzzy, no-c-format
msgid ""
"Query q = sess.createQuery(\"from DomesticCat cat\");\n"
"q.setFirstResult(20);\n"
"q.setMaxResults(10);\n"
"List cats = q.list();"
msgstr ""
"<![CDATA[Query q = sess.createQuery(\"from DomesticCat cat\");\n"
"q.setFirstResult(20);\n"
"q.setMaxResults(10);\n"
"List cats = q.list();]]>"

#. Tag: para
#: session_api.xml:322
#, no-c-format
msgid ""
"Hibernate knows how to translate this limit query into the native SQL of "
"your DBMS."
msgstr ""
"Hibernate 知道如何将这个有限定条件的查询转换成你的数据库的原生 SQL(native "
"SQL)。"

#. Tag: title
#: session_api.xml:327
#, no-c-format
msgid "Scrollable iteration"
msgstr "可滚动遍历(Scrollable iteration)"

#. Tag: para
#: session_api.xml:329
#, no-c-format
msgid ""
"If your JDBC driver supports scrollable <literal>ResultSets, the "
"<literal>Query interface can be used to obtain a "
"<literal>ScrollableResults object that allows flexible navigation "
"of the query results."
msgstr ""
"如果你的 JDBC 驱动支持可滚动的 <literal>ResuleSet,QueryScrollableResults,允许你在查询结果"
"中灵活游走。 "

#. Tag: programlisting
#: session_api.xml:334
#, fuzzy, no-c-format
msgid ""
"Query q = sess.createQuery(\"select cat.name, cat from DomesticCat cat \" +\n"
"                            \"order by cat.name\");\n"
"ScrollableResults cats = q.scroll();\n"
"if ( cats.first() ) {\n"
"\n"
"    // find the first name on each page of an alphabetical list of cats by "
"name\n"
"    firstNamesOfPages = new ArrayList();\n"
"    do {\n"
"        String name = cats.getString(0);\n"
"        firstNamesOfPages.add(name);\n"
"    }\n"
"    while ( cats.scroll(PAGE_SIZE) );\n"
"\n"
"    // Now get the first page of cats\n"
"    pageOfCats = new ArrayList();\n"
"    cats.beforeFirst();\n"
"    int i=0;\n"
"    while( ( PAGE_SIZE > i++ ) && cats.next() ) pageOfCats.add"
"( cats.get(1) );\n"
"\n"
"}\n"
"cats.close()"
msgstr ""
"<![CDATA[Query q = sess.createQuery(\"select cat.name, cat from DomesticCat "
"cat \" +\n"
"                            \"order by cat.name\");\n"
"ScrollableResults cats = q.scroll();\n"
"if ( cats.first() ) {\n"
"\n"
"    // find the first name on each page of an alphabetical list of cats by "
"name\n"
"    firstNamesOfPages = new ArrayList();\n"
"    do {\n"
"        String name = cats.getString(0);\n"
"        firstNamesOfPages.add(name);\n"
"    }\n"
"    while ( cats.scroll(PAGE_SIZE) );\n"
"\n"
"    // Now get the first page of cats\n"
"    pageOfCats = new ArrayList();\n"
"    cats.beforeFirst();\n"
"    int i=0;\n"
"    while( ( PAGE_SIZE > i++ ) && cats.next() ) pageOfCats.add( cats.get"
"(1) );\n"
"\n"
"}\n"
"cats.close()]]>"

#. Tag: para
#: session_api.xml:336
#, no-c-format
msgid ""
"Note that an open database connection and cursor is required for this "
"functionality. Use <literal>setMaxResult()/setFirstResult"
"()</literal> if you need offline pagination functionality."
msgstr ""
"请注意,使用此功能需要保持数据库连接(以及游标(cursor))处于一直打开状态。"
"如果你需要断开连接使用分页功能,请使用 <literal>setMaxResult()/"
"<literal>setFirstResult()。 "

#. Tag: title
#: session_api.xml:343
#, no-c-format
msgid "Externalizing named queries"
msgstr "外置命名查询(Externalizing named queries)"

#. Tag: para
#: session_api.xml:345
#, no-c-format
msgid ""
"Queries can also be configured as so called named queries using annotations "
"or Hibernate mapping documents. <literal>@NamedQuery and "
"<literal>@NamedQueries can be defined at the class level as seen "
"in <xref linkend=\"example-named-query-annotation\"/> . However their "
"definitions are global to the session factory/entity manager factory scope. "
"A named query is defined by its name and the actual query string."
msgstr ""

#. Tag: title
#: session_api.xml:355
#, no-c-format
msgid "Defining a named query using <classname>@NamedQuery"
msgstr ""

#. Tag: programlisting
#: session_api.xml:358
#, no-c-format
msgid ""
"@Entity\n"
"@NamedQuery(name=\"night.moreRecentThan\", query=\"select n from Night n "
"where n.date >= :date\")\n"
"public class Night {\n"
"    ...\n"
"}\n"
"\n"
"public class MyDao {\n"
"    doStuff() {\n"
"        Query q = s.getNamedQuery(\"night.moreRecentThan\");\n"
"        q.setDate( \"date\", aMonthAgo );\n"
"        List results = q.list();\n"
"        ...\n"
"    }\n"
"    ...\n"
"}"
msgstr ""

#. Tag: para
#: session_api.xml:361
#, fuzzy, no-c-format
msgid ""
"Using a mapping document can be configured using the <literal><query>CDATA section if your "
"query contains characters that could be interpreted as markup."
msgstr ""
"你可以在映射文件中定义命名查询(named queries)。如果你的查询串中包含可能被解"
"释为 XML 标记(markup)的字符,别忘了用<literal>CDATA包裹起来。"

#. Tag: title
#: session_api.xml:367
#, no-c-format
msgid "Defining a named query using <literal><query>"
msgstr ""

#. Tag: programlisting
#: session_api.xml:370
#, fuzzy, no-c-format
msgid ""
"<query name=\"ByNameAndMaximumWeight\"><![CDATA[\n"
"    from eg.DomesticCat as cat\n"
"        where cat.name = ?\n"
"        and cat.weight > ?\n"
"] ]></query>"
msgstr ""
"<![CDATA[]]>"

#. Tag: para
#: session_api.xml:373
#, fuzzy, no-c-format
msgid ""
"Parameter binding and executing is done programatically as seen in <xref "
"linkend=\"example-parameter-binding-named-query\"/>."
msgstr "参数绑定及执行以编程方式(programatically)完成:"

#. Tag: title
#: session_api.xml:377
#, no-c-format
msgid "Parameter binding of a named query"
msgstr ""

#. Tag: programlisting
#: session_api.xml:379
#, fuzzy, no-c-format
msgid ""
"Query q = sess.getNamedQuery(\"ByNameAndMaximumWeight\");\n"
"q.setString(0, name);\n"
"q.setInt(1, minWeight);\n"
"List cats = q.list();"
msgstr ""
"<![CDATA[Query q = sess.getNamedQuery(\"ByNameAndMaximumWeight\");\n"
"q.setString(0, name);\n"
"q.setInt(1, minWeight);\n"
"List cats = q.list();]]>"

#. Tag: para
#: session_api.xml:382
#, no-c-format
msgid ""
"The actual program code is independent of the query language that is used. "
"You can also define native SQL queries in metadata, or migrate existing "
"queries to Hibernate by placing them in mapping files."
msgstr ""
"请注意实际的程序代码与所用的查询语言无关,你也可在元数据中定义原生 SQL"
"(native SQL)查询,或将原有的其他的查询语句放在配置文件中,这样就可以让 "
"Hibernate 统一管理,达到迁移的目的。 "

#. Tag: para
#: session_api.xml:387
#, no-c-format
msgid ""
"Also note that a query declaration inside a <literal><hibernate-"
"mapping></literal> element requires a global unique name for the query, "
"while a query declaration inside a <literal><class> element "
"is made unique automatically by prepending the fully qualified name of the "
"class. For example <literal>eg.Cat.ByNameAndMaximumWeight."
msgstr ""
"也请注意在 <literal><hibernate-mapping> 元素中声明的查询必须"
"有一个全局唯一的名字,而在 <literal><class> 元素中声明的查询自"
"动具有全局名,是通过类的全名加以限定的。比如 <literal>eg.Cat."
"ByNameAndMaximumWeight</literal>。 "

#. Tag: title
#: session_api.xml:397
#, no-c-format
msgid "Filtering collections"
msgstr "过滤集合"

#. Tag: para
#: session_api.xml:399
#, no-c-format
msgid ""
"A collection <emphasis>filter is a special type of query that can "
"be applied to a persistent collection or array. The query string can refer "
"to <literal>this, meaning the current collection element."
msgstr ""
"集合<emphasis>过滤器(filter)是一种用于一个持久化集合或者数组的特"
"殊的查询。查询字符串中可以使用 <literal>\"this\" 来引用集合中的当前"
"元素。 "

#. Tag: programlisting
#: session_api.xml:404
#, fuzzy, no-c-format
msgid ""
"Collection blackKittens = session.createFilter(\n"
"    pk.getKittens(), \n"
"    \"where this.color = ?\")\n"
"    .setParameter( Color.BLACK, Hibernate.custom(ColorUserType.class) )\n"
"    .list()\n"
");"
msgstr ""
"<![CDATA[Collection blackKittens = session.createFilter(\n"
"    pk.getKittens(), \n"
"    \"where this.color = ?\")\n"
"    .setParameter( Color.BLACK, Hibernate.custom(ColorUserType.class) )\n"
"    .list()\n"
");]]>"

#. Tag: para
#: session_api.xml:406
#, no-c-format
msgid ""
"The returned collection is considered a bag that is 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 ""
"返回的集合可以被认为是一个包(bag,无顺序可重复的集合(collection)),它是所"
"给集合的副本。 原来的集合不会被改动(这与“过滤器(filter)”的隐含的含义不符,"
"不过与我们期待的行为一致)。 "

#. Tag: para
#: session_api.xml:411
#, no-c-format
msgid ""
"Observe that filters do not require a <literal>from clause, "
"although they can have one if required. Filters are not limited to returning "
"the collection elements themselves."
msgstr ""
"请注意过滤器(filter)并不需要 <literal>from 子句(当然需要的话它们"
"也可以加上)。过滤器(filter)不限定于只能返回集合元素本身。 "

#. Tag: programlisting
#: session_api.xml:415
#, fuzzy, no-c-format
msgid ""
"Collection blackKittenMates = session.createFilter(\n"
"    pk.getKittens(), \n"
"    \"select this.mate where this.color = eg.Color.BLACK.intValue\")\n"
"    .list();"
msgstr ""
"<![CDATA[Collection blackKittenMates = session.createFilter(\n"
"    pk.getKittens(), \n"
"    \"select this.mate where this.color = eg.Color.BLACK.intValue\")\n"
"    .list();]]>"

#. Tag: para
#: session_api.xml:417
#, no-c-format
msgid ""
"Even an empty filter query is useful, e.g. to load a subset of elements in a "
"large collection:"
msgstr ""
"即使无条件的过滤器(filter)也是有意义的。例如,用于加载一个大集合的子集: "

#. Tag: programlisting
#: session_api.xml:420
#, fuzzy, no-c-format
msgid ""
"Collection tenKittens = session.createFilter(\n"
"    mother.getKittens(), \"\")\n"
"    .setFirstResult(0).setMaxResults(10)\n"
"    .list();"
msgstr ""
"<![CDATA[Collection tenKittens = session.createFilter(\n"
"    mother.getKittens(), \"\")\n"
"    .setFirstResult(0).setMaxResults(10)\n"
"    .list();]]>"

#. Tag: title
#: session_api.xml:424
#, no-c-format
msgid "Criteria queries"
msgstr "条件查询(Criteria queries)"

#. Tag: para
#: session_api.xml:426
#, no-c-format
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 query "
"API for these cases:"
msgstr ""
"HQL 极为强大,但是有些人希望能够动态的使用一种面向对象 API 创建查询,而非在他"
"们的 Java 代码中嵌入字符串。对于那部分人来说,Hibernate 提供了直观的 "
"<literal>Criteria 查询 API。 "

#. Tag: programlisting
#: session_api.xml:431
#, fuzzy, no-c-format
msgid ""
"Criteria crit = session.createCriteria(Cat.class);\n"
"crit.add( Restrictions.eq( \"color\", eg.Color.BLACK ) );\n"
"crit.setMaxResults(10);\n"
"List cats = crit.list();"
msgstr ""
"<![CDATA[Criteria crit = session.createCriteria(Cat.class);\n"
"crit.add( Restrictions.eq( \"color\", eg.Color.BLACK ) );\n"
"crit.setMaxResults(10);\n"
"List cats = crit.list();]]>"

#. Tag: para
#: session_api.xml:433
#, fuzzy, no-c-format
msgid ""
"The <literal>Criteria and the associated Example 以及相关的样例(Example)API "
"将会在 <xref linkend=\"querycriteria\"/> 中详细讨论。"

#. Tag: title
#: session_api.xml:439
#, no-c-format
msgid "Queries in native SQL"
msgstr "使用原生 SQL 的查询"

#. Tag: para
#: session_api.xml:441
#, no-c-format
msgid ""
"You can express a query in SQL, using <literal>createSQLQuery() "
"and let Hibernate manage the mapping from result sets to objects. You can at "
"any time call <literal>session.connection() and use the JDBC "
"<literal>Connection directly. If you choose to use the Hibernate "
"API, you must enclose SQL aliases in braces:"
msgstr ""
"你可以使用 <literal>createSQLQuery() 方法,用 SQL 来描述查询,并由 "
"Hibernate 将结果集转换成对象。请注意,你可以在任何时候调用 <literal>session."
"connection()</literal> 来获得并使用 JDBC Connection 对"
"象。 如果你选择使用 Hibernate 的 API,你必须把 SQL 别名用大括号包围起来: "

#. Tag: programlisting
#: session_api.xml:448
#, fuzzy, no-c-format
msgid ""
"List cats = session.createSQLQuery(\"SELECT {cat.*} FROM CAT {cat} WHERE "
"ROWNUM<10\")\n"
"    .addEntity(\"cat\", Cat.class)\n"
".list();"
msgstr ""
"<![CDATA[List cats = session.createSQLQuery(\"SELECT {cat.*} FROM CAT {cat} "
"WHERE ROWNUM<10\")\n"
"    .addEntity(\"cat\", Cat.class)\n"
".list();]]>"

#. Tag: programlisting
#: session_api.xml:450
#, fuzzy, no-c-format
msgid ""
"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 ""
"<![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()]]>"

#. Tag: para
#: session_api.xml:452
#, fuzzy, no-c-format
msgid ""
"SQL queries can 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:459
#, no-c-format
msgid "Modifying persistent objects"
msgstr "修改持久对象"

#. Tag: para
#: session_api.xml:461
#, no-c-format
msgid ""
"<emphasis>Transactional persistent instances (i.e. objects "
"loaded, saved, created or queried by the <literal>Session) can be "
"manipulated by the application, and any changes to persistent state will be "
"persisted when the <literal>Session is flushed, which has a different "
"purpose) to make your modifications persistent. The most straightforward way "
"to update the state of an object is to <literal>load() it and then "
"manipulate it directly while the <literal>Session is open:"
msgstr ""
"<emphasis>事务中的持久实例(就是通过 session 装"
"载、保存、创建或者查询出的对象) 被应用程序操作所造成的任何修改都会在 "
"<literal>Session 被刷出(flushed)的时候被持久"
"化(本章后面会详细讨论)。这里不需要调用某个特定的方法(比如 <literal>update"
"()</literal>,设计它的目的是不同的)将你的修改持久化。所以最直接的更新一个对"
"象的方法就是在 <literal>Session 处于打开状态时 load() to load an object and an SQL "
"<literal>UPDATE to persist its updated state. Hibernate offers an "
"alternate approach by using detached instances."
msgstr ""
"有时这种程序模型效率低下,因为它在同一 Session 里需要一条 SQL "
"<literal>SELECT 语句(用于加载对象) 以及一条 SQL UPDATE or Session."
"merge()</literal> methods:"
msgstr ""
"Hibernate 通过提供 <literal>Session.update()Session."
"merge()</literal>  重新关联脱管实例的办法来支持这种模型。"

#. Tag: programlisting
#: session_api.xml:495
#, fuzzy, no-c-format
msgid ""
"// 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 ""
"<![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]]>"

#. Tag: para
#: session_api.xml:497
#, no-c-format
msgid ""
"If the <literal>Cat with identifier catId had "
"already been loaded by <literal>secondSession when the application "
"tried to reattach it, an exception would have been thrown."
msgstr ""
"如果具有 <literal>catId 持久化标识的 Cat 之前已"
"经被<literal>另一Session(secondSession)装载了, 应用程序进行重关"
"联操作(reattach)的时候会抛出一个异常。"

#. Tag: para
#: session_api.xml:502
#, no-c-format
msgid ""
"Use <literal>update() if you are certain that the session does not "
"contain an already persistent instance with the same identifier. Use "
"<literal>merge() if you want to merge your modifications at any "
"time without consideration of the state of the session. In other words, "
"<literal>update() is usually the first method you would call in a "
"fresh session, ensuring that the reattachment of your detached instances is "
"the first operation that is executed."
msgstr ""
"如果你确定当前 session 没有包含与之具有相同持久化标识的持久实例,使用 "
"<literal>update()。如果想随时合并你的的改动而不考虑 session 的状"
"态,使用 <literal>merge()。换句话说,在一个新 session 中通常第一个"
"调用的是 <literal>update() 方法,以便保证重新关联脱管(detached)对"
"象的操作首先被执行。 "

#. Tag: para
#: session_api.xml:510
#, fuzzy, no-c-format
msgid ""
"The application should individually <literal>update() detached "
"instances that are reachable from the given detached instance "
"<emphasis>only if it wants their state to be updated. This can be "
"automated using <emphasis>transitive persistence. See 在这种情况),可以对该相关联的脱管对象单独"
"调用 <literal>update() 当然这些可以自动完成,即通过使用传"
"播性持久化(transitive persistence)</emphasis>,请看  method also allows an application to "
"reassociate an object with a new session. However, the detached instance has "
"to be unmodified."
msgstr ""
"<literal>lock() 方法也允许程序重新关联某个对象到一个新 session 上。"
"不过,该脱管(detached)的对象必须是没有修改过的。"

#. Tag: programlisting
#: session_api.xml:520
#, fuzzy, no-c-format
msgid ""
"//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 ""
"<![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);]]>"

#. Tag: para
#: session_api.xml:522
#, no-c-format
msgid ""
"Note that <literal>lock() can be used with various "
"<literal>LockModes. See the API documentation and the chapter on "
"transaction handling for more information. Reattachment is not the only "
"usecase for <literal>lock()."
msgstr ""
"请注意,<literal>lock() 可以搭配多种 LockMode,"
"更多信息请阅读 API 文档以及关于事务处理(transaction handling)的章节。重新关"
"联不是 <literal>lock() 的唯一用途。 "

#. Tag: para
#: session_api.xml:527
#, fuzzy, no-c-format
msgid ""
"Other models for long units of work are discussed in <xref linkend="
"\"transactions-optimistic\"/>."
msgstr ""
"其他用于长时间工作单元的模型会在 <xref linkend=\"transactions-optimistic\"/> "
"中讨论。"

#. Tag: title
#: session_api.xml:532
#, no-c-format
msgid "Automatic state detection"
msgstr "自动状态检测"

#. Tag: para
#: session_api.xml:534
#, no-c-format
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() method implements this functionality."
msgstr ""
"Hibernate 的用户曾要求一个既可自动分配新持久化标识(identifier)保存瞬时"
"(transient)对象,又可更新/重新关联脱管(detached)实例的通用方法。"
"<literal>saveOrUpdate() 方法实现了这个功能。"

#. Tag: programlisting
#: session_api.xml:540
#, fuzzy, no-c-format
msgid ""
"// 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 ""
"<![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)]]>"

#. Tag: para
#: session_api.xml:542
#, no-c-format
msgid ""
"The usage and semantics of <literal>saveOrUpdate() 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(), saveOrUpdate(), or "
"<literal>merge(). Some whole applications will never use either of "
"these methods."
msgstr ""
"<literal>saveOrUpdate() 用途和语义可能会使新用户感到迷惑。首先,只"
"要你没有尝试在某个  session 中使用来自另一 session 的实例,你就应该不需要使"
"用 <literal>update(), saveOrUpdate(),或 "
"<literal>merge()。有些程序从来不用这些方法。"

#. Tag: para
#: session_api.xml:549
#, no-c-format
msgid ""
"Usually <literal>update() or saveOrUpdate() are "
"used in the following scenario:"
msgstr ""
"通常下面的场景会使用 <literal>update() 或 saveOrUpdate() 方法持久这些改动"

#. Tag: para
#: session_api.xml:576
#, no-c-format
msgid "<literal>saveOrUpdate() does the following:"
msgstr "<literal>saveOrUpdate() 做下面的事:"

#. Tag: para
#: session_api.xml:580
#, no-c-format
msgid "if the object is already persistent in this session, do nothing"
msgstr "如果对象已经在本 session 中持久化了,不做任何事"

#. Tag: para
#: session_api.xml:585
#, no-c-format
msgid ""
"if another object associated with the session has the same identifier, throw "
"an exception"
msgstr ""
"如果另一个与本 session 关联的对象拥有相同的持久化标识(identifier),抛出一个"
"异常"

#. Tag: para
#: session_api.xml:590
#, no-c-format
msgid "if the object has no identifier property, <literal>save() it"
msgstr ""
"如果对象没有持久化标识(identifier)属性,对其调用 <literal>save()"

#. Tag: para
#: session_api.xml:595
#, no-c-format
msgid ""
"if the object's identifier has the value assigned to a newly instantiated "
"object, <literal>save() it"
msgstr ""
"如果对象的持久标识(identifier)表明其是一个新实例化的对象,对其调用 "
"<literal>save()。"

#. Tag: para
#: session_api.xml:600
#, no-c-format
msgid ""
"if the object is versioned by a <literal><version> or "
"<literal><timestamp>, and the version property value is the "
"same value assigned to a newly instantiated object, <literal>save() 或 "
"<literal><timestamp>)并且版本属性的值表明其是一个新实例化的"
"对象,<literal>save() 它。 "

#. Tag: para
#: session_api.xml:608
#, no-c-format
msgid "otherwise <literal>update() the object"
msgstr "否则 <literal>update() 这个对象"

#. Tag: para
#: session_api.xml:612
#, no-c-format
msgid "and <literal>merge() is very different:"
msgstr "<literal>merge() 可非常不同:"

#. Tag: para
#: session_api.xml:616
#, no-c-format
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 中存在相同持久化标识(identifier)的实例,用用户给出的对象的状态"
"覆盖旧有的持久实例"

#. Tag: para
#: session_api.xml:622
#, no-c-format
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 没有相应的持久实例,则尝试从数据库中加载,或创建新的持久化实例"

#. Tag: para
#: session_api.xml:628
#, no-c-format
msgid "the persistent instance is returned"
msgstr "最后返回该持久实例"

#. Tag: para
#: session_api.xml:632
#, no-c-format
msgid ""
"the given instance does not become associated with the session, it remains "
"detached"
msgstr "用户给出的这个对象没有被关联到 session 上,它依旧是脱管的"

#. Tag: title
#: session_api.xml:639
#, no-c-format
msgid "Deleting persistent objects"
msgstr "删除持久对象"

#. Tag: para
#: session_api.xml:641
#, no-c-format
msgid ""
"<literal>Session.delete() will remove an object's state from the "
"database. Your application, however, can still hold a reference to a deleted "
"object. It is best to think of <literal>delete() as making a "
"persistent instance, transient."
msgstr ""
"使用 <literal>Session.delete() 会把对象的状态从数据库中移除。当然,"
"你的应用程序可能仍然持有一个指向已删除对象的引用。所以,最好这样理解:"
"<literal>delete() 的用途是把一个持久实例变成瞬时(transient)实"
"例。 "

#. Tag: programlisting
#: session_api.xml:646
#, fuzzy, no-c-format
msgid "sess.delete(cat);"
msgstr "<![CDATA[sess.delete(cat);]]>"

#. Tag: para
#: session_api.xml:648
#, no-c-format
msgid ""
"You can delete objects in any order, without risk of foreign key constraint "
"violations. It is still possible to violate a <literal>NOT NULL "
"constraint on a foreign key column by deleting objects in the wrong order, e."
"g. if you delete the parent, but forget to delete the children."
msgstr ""
"你可以用你喜欢的任何顺序删除对象,不用担心外键约束冲突。当然,如果你搞错了顺"
"序,还是有可能引发在外键字段定义的 <literal>NOT NULL 约束冲突。例如"
"你删除了父对象,但是忘记删除其子对象。"

#. Tag: title
#: session_api.xml:656
#, no-c-format
msgid "Replicating object between two different datastores"
msgstr "在两个不同数据库间复制对象"

#. Tag: para
#: session_api.xml:658
#, no-c-format
msgid ""
"It is sometimes useful to be able to take a graph of persistent instances "
"and make them persistent in a different datastore, without regenerating "
"identifier values."
msgstr ""
"偶尔会用到不重新生成持久化标识(identifier),将持久实例以及其关联的实例持久"
"到不同的数据库中的操作。 "

#. Tag: programlisting
#: session_api.xml:662
#, fuzzy, no-c-format
msgid ""
"//retrieve a cat from one database\n"
"Session session1 = factory1.openSession();\n"
"Transaction tx1 = session1.beginTransaction();\n"
"Cat cat = session1.get(Cat.class, catId);\n"
"tx1.commit();\n"
"session1.close();\n"
"\n"
"//reconcile with a second database\n"
"Session session2 = factory2.openSession();\n"
"Transaction tx2 = session2.beginTransaction();\n"
"session2.replicate(cat, ReplicationMode.LATEST_VERSION);\n"
"tx2.commit();\n"
"session2.close();"
msgstr ""
"<![CDATA[//retrieve a cat from one database\n"
"Session session1 = factory1.openSession();\n"
"Transaction tx1 = session1.beginTransaction();\n"
"Cat cat = session1.get(Cat.class, catId);\n"
"tx1.commit();\n"
"session1.close();\n"
"\n"
"//reconcile with a second database\n"
"Session session2 = factory2.openSession();\n"
"Transaction tx2 = session2.beginTransaction();\n"
"session2.replicate(cat, ReplicationMode.LATEST_VERSION);\n"
"tx2.commit();\n"
"session2.close();]]>"

#. Tag: para
#: session_api.xml:664
#, no-c-format
msgid ""
"The <literal>ReplicationMode determines how replicate() 决定在和数据库中已存在记录由冲突时,"
"<literal>replicate() 如何处理。 "

#. Tag: para
#: session_api.xml:670
#, no-c-format
msgid ""
"<literal>ReplicationMode.IGNORE: ignores the object when there is "
"an existing database row with the same identifier"
msgstr ""
"<literal>ReplicationMode.IGNORE:当某个现有数据库记录具有相同标识符"
"时忽略它"

#. Tag: para
#: session_api.xml:675
#, no-c-format
msgid ""
"<literal>ReplicationMode.OVERWRITE: overwrites any existing "
"database row with the same identifier"
msgstr ""
"<literal>ReplicationMode.OVERWRITE:用相同的标识符覆盖现有数据库记"
"录"

#. Tag: para
#: session_api.xml:680
#, no-c-format
msgid ""
"<literal>ReplicationMode.EXCEPTION: throws an exception if there "
"is an existing database row with the same identifier"
msgstr ""
"<literal>ReplicationMode.EXCEPTION:当某个现有数据库记录具有相同标"
"识符时抛出异常"

#. Tag: para
#: session_api.xml:686
#, no-c-format
msgid ""
"<literal>ReplicationMode.LATEST_VERSION: overwrites the row if its "
"version number is earlier than the version number of the object, or ignore "
"the object otherwise"
msgstr ""
"<literal>ReplicationMode.LATEST_VERSION:如果当前的版本较新,则覆"
"盖,否则忽略"

#. Tag: para
#: session_api.xml:692
#, no-c-format
msgid ""
"Usecases for this feature include reconciling data entered into different "
"database instances, upgrading system configuration information during "
"product upgrades, rolling back changes made during non-ACID transactions and "
"more."
msgstr ""
"这个功能的用途包括使录入的数据在不同数据库中一致,产品升级时升级系统配置信"
"息,回滚 non-ACID 事务中的修改等等。(译注,non-ACID,非 ACID;ACID,Atomic,"
"Consistent,Isolated and Durable 的缩写)"

#. Tag: title
#: session_api.xml:699
#, no-c-format
msgid "Flushing the Session"
msgstr "Session 刷出(flush)"

#. Tag: para
#: session_api.xml:701
#, no-c-format
msgid ""
"Sometimes the <literal>Session will execute the SQL statements "
"needed to synchronize the JDBC connection's state with the state of objects "
"held in memory. This process, called <emphasis>flush, occurs by "
"default at the following points:"
msgstr ""
"每间隔一段时间,<literal>Session 会执行一些必需的 SQL 语句来把内存"
"中的对象的状态同步到 JDBC 连接中。这个过程被称为<emphasis>刷出(flush)"
msgstr "在调用 <literal>org.hibernate.Transaction.commit() 的时候"

#. Tag: para
#: session_api.xml:718
#, no-c-format
msgid "from <literal>Session.flush()"
msgstr "在调用 <literal>Session.flush() 的时候"

#. Tag: para
#: session_api.xml:722
#, no-c-format
msgid "The SQL statements are issued in the following order:"
msgstr "涉及的 SQL 语句会按照下面的顺序发出执行: "

#. Tag: para
#: session_api.xml:726
#, no-c-format
msgid ""
"all entity insertions in the same order the corresponding objects were saved "
"using <literal>Session.save()"
msgstr ""
"所有对实体进行插入的语句,其顺序按照对象执行 <literal>Session.save()"
msgstr ""
"所有对实体进行删除的语句,其顺序按照对象执行 <literal>Session.delete() ID generation "
"are inserted when they are saved."
msgstr ""
"有一个例外是,如果对象使用 <literal>native 方式来生成 ID(持久化标"
"识)的话,它们一执行 save 就会被插入。"

#. Tag: para
#: session_api.xml:755
#, no-c-format
msgid ""
"Except when you explicitly <literal>flush(), there are absolutely "
"no guarantees about <emphasis>when the Session "
"executes the JDBC calls, only the <emphasis>order in which they "
"are executed. However, Hibernate does guarantee that the <literal>Query.list"
"(..)</literal> will never return stale or incorrect data."
msgstr ""
"除非你明确地发出了 <literal>flush() 指令,关于 Session 何"
"时</emphasis>会执行这些 JDBC 调用是完全无法保证的,只能保证它们执行的前后顺"
"序。当然,Hibernate 保证,<literal>Query.list(..) 绝对不会返回已经"
"失效的数据,也不会返回错误数据。 "

#. Tag: para
#: session_api.xml:762
#, fuzzy, no-c-format
msgid ""
"It is possible to change the default behavior so that flush occurs less "
"frequently. The <literal>FlushMode class defines three different "
"modes: only flush at commit time when the Hibernate <literal>Transaction is called explicitly. The last "
"mode is useful for long running units of work, where a <literal>Session 类定义了三种不同的方式。仅在提交时刷出(仅当 "
"Hibernate 的 <literal>Transaction API 被使用时有效),按照刚才说的"
"方式刷出,以及除非明确使用 <literal>flush() 否则从不刷出。 最后一种"
"模式对于那些需要长时间保持 <literal>Session 为打开或者断线状态的长"
"时间运行的工作单元很有用。(参见 <xref linkend=\"transactions-optimistic-"
"longsession\"/>)。"

#. Tag: programlisting
#: session_api.xml:772
#, fuzzy, no-c-format
msgid ""
"sess = sf.openSession();\n"
"Transaction tx = sess.beginTransaction();\n"
"sess.setFlushMode(FlushMode.COMMIT); // allow queries to return stale state\n"
"\n"
"Cat izi = (Cat) sess.load(Cat.class, id);\n"
"izi.setName(iznizi);\n"
"\n"
"// might return stale data\n"
"sess.find(\"from Cat as cat left outer join cat.kittens kitten\");\n"
"\n"
"// change to izi is not flushed!\n"
"...\n"
"tx.commit(); // flush occurs\n"
"sess.close();"
msgstr ""
"<![CDATA[sess = sf.openSession();\n"
"Transaction tx = sess.beginTransaction();\n"
"sess.setFlushMode(FlushMode.COMMIT); // allow queries to return stale state\n"
"\n"
"Cat izi = (Cat) sess.load(Cat.class, id);\n"
"izi.setName(iznizi);\n"
"\n"
"// might return stale data\n"
"sess.find(\"from Cat as cat left outer join cat.kittens kitten\");\n"
"\n"
"// change to izi is not flushed!\n"
"...\n"
"tx.commit(); // flush occurs\n"
"sess.close();]]>"

#. Tag: para
#: session_api.xml:774
#, fuzzy, no-c-format
msgid ""
"During flush, an exception might occur (e.g. if a DML operation violates a "
"constraint). Since handling exceptions involves some understanding of "
"Hibernate's transactional behavior, we discuss it in <xref linkend="
"\"transactions\"/>."
msgstr ""
"刷出(flush)期间,可能会抛出异常(例如一个 DML 操作违反了约束)。异常处理涉"
"及到对 Hibernate 事务性行为的理解,因此我们将在 <xref linkend=\"transactions"
"\"/> 中讨论。 "

#. Tag: title
#: session_api.xml:781
#, no-c-format
msgid "Transitive persistence"
msgstr "传播性持久化(transitive persistence)"

#. Tag: para
#: session_api.xml:783
#, no-c-format
msgid ""
"It is quite cumbersome to save, delete, or reattach individual objects, "
"especially if you deal with a graph of associated objects. A common case is "
"a parent/child relationship. Consider the following example:"
msgstr ""
"对每一个对象都要执行保存,删除或重关联操作让人感觉有点麻烦,尤其是在处理许多"
"彼此关联的对象的时候。一个常见的例子是父子关系。考虑下面的例子:"

#. Tag: para
#: session_api.xml:788
#, no-c-format
msgid ""
"If the children in a parent/child relationship would be value typed (e.g. a "
"collection of addresses or strings), their life cycle would depend on the "
"parent and no further action would be required for convenient \"cascading\" "
"of state changes. When the parent is saved, the value-typed child objects "
"are saved and when the parent is deleted, the children will be deleted, etc. "
"This works for operations such as the removal of a child from the "
"collection. Since value-typed objects cannot have shared references, "
"Hibernate will detect this and delete the child from the database."
msgstr ""
"如果一个父子关系中的子对象是值类型(value typed)(例如,地址或字符串的集合)"
"的,他们的生命周期会依赖于父对象,可以享受方便的级联操作(Cascading),不需要"
"额外的动作。父对象被保存时,这些值类型(value typed)子对象也将被保存;父对象"
"被删除时,子对象也将被删除。这对将一个子对象从集合中移除是同样有效:"
"Hibernate 会检测到,并且因为值类型(value typed)的对象不可能被其他对象引用,"
"所以 Hibernate 会在数据库中删除这个子对象。 "

#. Tag: para
#: session_api.xml:798
#, no-c-format
msgid ""
"Now consider the same scenario with parent and child objects being entities, "
"not value-types (e.g. categories and items, or parent and child cats). "
"Entities have their own life cycle and support shared references. Removing "
"an entity from the collection does not mean it can be deleted), and there is "
"by default no cascading of state from one entity to any other associated "
"entities. Hibernate does not implement <emphasis>persistence by "
"reachability</emphasis> by default."
msgstr ""
"现在考虑同样的场景,不过父子对象都是实体(entities)类型,而非值类型(value "
"typed)(例如,类别与个体,或母猫和小猫)。实体有自己的生命期,允许共享对其的"
"引用(因此从集合中移除一个实体,不意味着它可以被删除),并且实体到其他关联实"
"体之间默认没有级联操作的设置。 Hibernate 默认不实现所谓的<emphasis>可到达即持"
"久化(persistence by reachability)</emphasis>的策略。 "

#. Tag: para
#: session_api.xml:806
#, no-c-format
msgid ""
"For each basic operation of the Hibernate session - including "
"<literal>persist(), merge(), saveOrUpdate(), delete(), lock(), refresh(), "
"evict(), replicate()</literal> - there is a corresponding cascade style. "
"Respectively, the cascade styles are named <literal>create, merge, save-"
"update, delete, lock, refresh, evict, replicate</literal>. If you want an "
"operation to be cascaded along an association, you must indicate that in the "
"mapping document. For example:"
msgstr ""
"每个 Hibernate session 的基本操作 — 包括 <literal>persist(), merge(), "
"saveOrUpdate(), delete(), lock(), refresh(), evict(), replicate()</literal> "
"— 都有对应的级联风格(cascade style)。这些级联风格(cascade style)风格分别"
"命名为  <literal>create, merge, save-update, delete, lock, refresh, evict, "
"replicate</literal>。如果你希望一个操作被顺着关联关系级联传播,你必须在映射文"
"件中指出这一点。例如:"

#. Tag: programlisting
#: session_api.xml:814
#, fuzzy, no-c-format
msgid "<one-to-one name=\"person\" cascade=\"persist\"/>"
msgstr "<![CDATA["

#. Tag: para
#: session_api.xml:816
#, no-c-format
msgid "Cascade styles my be combined:"
msgstr "级联风格(cascade style)是可组合的:"

#. Tag: programlisting
#: session_api.xml:818
#, fuzzy, no-c-format
msgid "<one-to-one name=\"person\" cascade=\"persist,delete,lock\"/>"
msgstr ""
"<![CDATA["

#. Tag: para
#: session_api.xml:820
#, no-c-format
msgid ""
"You can even use <literal>cascade=\"all\" to specify that "
"<emphasis>all operations should be cascaded along the "
"association. The default <literal>cascade=\"none\" specifies that "
"no operations are to be cascaded."
msgstr ""
"你可以使用 <literal>cascade=\"all\" 来指定全部"
"操作都顺着关联关系级联(cascaded)。默认值是 <literal>cascade=\"none\" attribute taking an array of "
"<classname>CascadeType as a value. The cascade concept in JPA is "
"very is similar to the transitive persistence and cascading of operations as "
"described above, but with slightly different semantics and cascading types:"
msgstr ""

#. Tag: para
#: session_api.xml:834
#, no-c-format
msgid ""
"<literal>CascadeType.PERSIST: cascades the persist (create) "
"operation to associated entities persist() is called or if the entity is "
"managed"
msgstr ""

#. Tag: para
#: session_api.xml:840
#, no-c-format
msgid ""
"<literal>CascadeType.MERGE: cascades the merge operation to "
"associated entities if merge() is called or if the entity is managed"
msgstr ""

#. Tag: para
#: session_api.xml:846
#, no-c-format
msgid ""
"<literal>CascadeType.REMOVE: cascades the remove operation to "
"associated entities if delete() is called"
msgstr ""

#. Tag: para
#: session_api.xml:851
#, no-c-format
msgid ""
"<literal>CascadeType.REFRESH: cascades the refresh operation to "
"associated entities if refresh() is called"
msgstr ""

#. Tag: para
#: session_api.xml:856
#, no-c-format
msgid ""
"<literal>CascadeType.DETACH: cascades the detach operation to "
"associated entities if detach() is called"
msgstr ""

#. Tag: para
#: session_api.xml:861
#, fuzzy, no-c-format
msgid "<literal>CascadeType.ALL: all of the above"
msgstr "<literal>saveOrUpdate() 做下面的事:"

#. Tag: para
#: session_api.xml:866
#, no-c-format
msgid ""
"CascadeType.ALL also covers Hibernate specific operations like save-update, "
"lock etc..."
msgstr ""

#. Tag: para
#: session_api.xml:870
#, no-c-format
msgid ""
"A special cascade style, <literal>delete-orphan, applies only to "
"one-to-many associations, and indicates that the <literal>delete() "
"operation should be applied to any child object that is removed from the "
"association. Using annotations there is no <literal>CascadeType.DELETE-"
"ORPHAN</literal> equivalent. Instead you can use the attribute "
"<literal>orphanRemoval as seen in  collection or an associated entity is "
"dereferenced from a <classname>@OneToOne association, this "
"associated entity can be marked for deletion if <literal>orphanRemoval with orphanRemoval"
msgstr ""

#. Tag: programlisting
#: session_api.xml:886
#, no-c-format
msgid ""
"@Entity \n"
"public class Customer {\n"
"   private Set<Order> orders;\n"
"\n"
"   @OneToMany(cascade=CascadeType.ALL, orphanRemoval=true) \n"
"   public Set<Order> getOrders() { return orders; }\n"
"\n"
"   public void setOrders(Set<Order> orders) { this.orders = orders; }\n"
"\n"
"   [...]\n"
"}\n"
"\n"
"@Entity \n"
"public class Order { ... }\n"
"\n"
"Customer customer = em.find(Customer.class, 1l);\n"
"Order order = em.find(Order.class, 1l);\n"
"customer.getOrders().remove(order); //order will be deleted by cascade"
msgstr ""

#. Tag: para
#: session_api.xml:889
#, no-c-format
msgid "Recommendations:"
msgstr "建议:"

#. Tag: para
#: session_api.xml:893
#, fuzzy, no-c-format
msgid ""
"It does not usually make sense to enable cascade on a many-to-one or many-to-"
"many association. In fact the <literal>@ManyToOne and "
"<literal>@ManyToMany don't even offer a orphanRemoval<many-to-"
"many></literal> 关系中应用级联(cascade)没什么意义。级联(cascade)通常"
"在 <literal><one-to-one><one-to-many> by specifying "
"<literal>cascade=\"all,delete-orphan\"(@OneToMany"
"(cascade=CascadeType.ALL, orphanRemoval=true)</literal>)."
msgstr ""
"如果子对象的寿命限定在父亲对象的寿命之内,可通过指定 <literal>cascade=\"all,"
"delete-orphan\"</literal> 将其变为自动生命周期管理的对象"
"(lifecycle object)</emphasis>。 "

#. Tag: para
#: session_api.xml:909
#, no-c-format
msgid ""
"Otherwise, you might not need cascade at all. But if you think that you will "
"often be working with the parent and children together in the same "
"transaction, and you want to save yourself some typing, consider using "
"<literal>cascade=\"persist,merge,save-update\"."
msgstr ""
"其他情况,你可根本不需要级联(cascade)。但是如果你认为你会经常在某个事务中同"
"时用到父对象与子对象,并且你希望少打点儿字,可以考虑使用   <literal>cascade="
"\"persist,merge,save-update\"</literal>。"

#. Tag: para
#: session_api.xml:917
#, no-c-format
msgid ""
"Mapping an association (either a single valued association, or a collection) "
"with <literal>cascade=\"all\" marks the association as a "
"<emphasis>parent/child style relationship where save/update/"
"delete of the parent results in save/update/delete of the child or children."
msgstr ""
"可以使用 <literal>cascade=\"all\" 将一个关联关系(无论是对值对象的"
"关联,或者对一个集合的关联)标记为<emphasis>父/子关系的关联。 这样"
"对父对象进行 save/update/delete 操作就会导致子对象也进行 save/update/delete "
"操作。"

#. Tag: para
#: session_api.xml:923
#, fuzzy, no-c-format
msgid ""
"Furthermore, a mere reference to a child from a persistent parent will "
"result in save/update of the child. This metaphor is incomplete, however. A "
"child which becomes unreferenced by its parent is <emphasis>not "
"automatically deleted, except in the case of a one-to-many association "
"mapped with <literal>cascade=\"delete-orphan\". The precise "
"semantics of cascading operations for a parent/child relationship are as "
"follows:"
msgstr ""
"此外,一个持久的父对象对子对象的浅引用(mere reference)会导致子对象被同步 "
"save/update。不过,这个隐喻(metaphor)的说法并不完整。除非关联是 "
"<literal><one-to-many> 关联并且被标记为 cascade="
"\"delete-orphan\"</literal>,否则父对象失去对某个子对象的引用不会, all children are "
"passed to <literal>persist()"
msgstr ""
"如果父对象被 <literal>persist(),那么所有子对象也会被 "
"<literal>persist()"

#. Tag: para
#: session_api.xml:939
#, no-c-format
msgid ""
"If a parent is passed to <literal>merge(), all children are passed "
"to <literal>merge()"
msgstr ""
"如果父对象被 <literal>merge(),那么所有子对象也会被 merge"
"()</literal>"

#. Tag: para
#: session_api.xml:944
#, no-c-format
msgid ""
"If a parent is passed to <literal>save(), update()saveOrUpdate(), all children are passed to "
"<literal>saveOrUpdate()"
msgstr ""
"如果父对象被 <literal>save(),update() 或  "
"<literal>saveOrUpdate(),那么所有子对象则会被 saveOrUpdate"
"()</literal>"

#. Tag: para
#: session_api.xml:950
#, no-c-format
msgid ""
"If a transient or detached child becomes referenced by a persistent parent, "
"it is passed to <literal>saveOrUpdate()"
msgstr ""
"如果某个持久的父对象引用了瞬时(transient)或者脱管(detached)的子对象,那么"
"子对象将会被 <literal>saveOrUpdate()"

#. Tag: para
#: session_api.xml:956
#, no-c-format
msgid ""
"If a parent is deleted, all children are passed to <literal>delete()"

#. Tag: para
#: session_api.xml:961
#, no-c-format
msgid ""
"If a child is dereferenced by a persistent parent, <emphasis>nothing special "
"happens</emphasis> - the application should explicitly delete the child if "
"necessary - unless <literal>cascade=\"delete-orphan\", in which "
"case the \"orphaned\" child is deleted."
msgstr ""
"除非被标记为 <literal>cascade=\"delete-orphan\"(删除“孤儿”模式,此"
"时不被任何一个父对象引用的子对象会被删除),否则子对象失掉父对象对其的引用"
"时,<emphasis>什么事也不会发生。如果有特殊需要,应用程序可通过显式"
"调用 delete() 删除子对象。"

#. Tag: para
#: session_api.xml:969
#, no-c-format
msgid ""
"Finally, note that cascading of operations can be applied to an object graph "
"at <emphasis>call time or at flush time. All "
"operations, if enabled, are cascaded to associated entities reachable when "
"the operation is executed. However, <literal>save-update and "
"<literal>delete-orphan are transitive for all associated entities "
"reachable during flush of the <literal>Session."
msgstr ""
"最后,注意操作的级联可能是在<emphasis>调用期(call time)或者"
"<emphasis>写入期(flush time)作用到对象图上的。所有的操作,如果允"
"许,都在操作被执行的时候级联到可触及的关联实体上。然而,<literal>save-upatedelete-orphan 是在Session "
"flush 的时候才作用到所有可触及的被关联对象上的。 "

#. Tag: title
#: session_api.xml:979
#, no-c-format
msgid "Using metadata"
msgstr "使用元数据"

#. Tag: para
#: session_api.xml:981
#, no-c-format
msgid ""
"Hibernate requires a rich meta-level model of all entity and value types. "
"This model can be useful to the application itself. For example, the "
"application might use Hibernate's metadata to implement a \"smart\" deep-"
"copy algorithm that understands which objects should be copied (eg. mutable "
"value types) and which objects that should not (e.g. immutable value types "
"and, possibly, associated entities)."
msgstr ""
"Hibernate 中有一个非常丰富的元级别(meta-level)的模型,含有所有的实体和值类"
"型数据的元数据。 有时这个模型对应用程序本身也会非常有用。比如说,应用程序可能"
"在实现一种“智能”的深度拷贝算法时,通过使用 Hibernate 的元数据来了解哪些对象应"
"该被拷贝(比如,可变的值类型数据),那些不应该(不可变的值类型数据,也许还有"
"某些被关联的实体)。 "

#. Tag: para
#: session_api.xml:988
#, no-c-format
msgid ""
"Hibernate exposes metadata via the <literal>ClassMetadata and "
"<literal>CollectionMetadata interfaces and the Type."
msgstr ""
"Hibernate 提供了 <literal>ClassMetadata 接口,"
"<literal>CollectionMetadata 接口和 Type 层次体系"
"来访问元数据。可以通过  <literal>SessionFactory 获取元数据接口的实"
"例。 "

#. Tag: programlisting
#: session_api.xml:993
#, fuzzy, no-c-format
msgid ""
"Cat fritz = ......;\n"
"ClassMetadata catMeta = sessionfactory.getClassMetadata(Cat.class);\n"
"\n"
"Object[] propertyValues = catMeta.getPropertyValues(fritz);\n"
"String[] propertyNames = catMeta.getPropertyNames();\n"
"Type[] propertyTypes = catMeta.getPropertyTypes();\n"
"\n"
"// get a Map of all properties which are not collections or associations\n"
"Map namedValues = new HashMap();\n"
"for ( int i=0; i<propertyNames.length; i++ ) {\n"
"    if ( !propertyTypes[i].isEntityType() && !propertyTypes[i]."
"isCollectionType() ) {\n"
"        namedValues.put( propertyNames[i], propertyValues[i] );\n"
"    }\n"
"}"
msgstr ""
"<![CDATA[Cat fritz = ......;\n"
"ClassMetadata catMeta = sessionfactory.getClassMetadata(Cat.class);\n"
"\n"
"Object[] propertyValues = catMeta.getPropertyValues(fritz);\n"
"String[] propertyNames = catMeta.getPropertyNames();\n"
"Type[] propertyTypes = catMeta.getPropertyTypes();\n"
"\n"
"// get a Map of all properties which are not collections or associations\n"
"Map namedValues = new HashMap();\n"
"for ( int i=0; i<propertyNames.length; i++ ) {\n"
"    if ( !propertyTypes[i].isEntityType() && !propertyTypes[i]."
"isCollectionType() ) {\n"
"        namedValues.put( propertyNames[i], propertyValues[i] );\n"
"    }\n"
"}]]>"

#, fuzzy
#~ msgid ""
#~ "Hibernate does not offer its own API for direct execution of "
#~ "<literal>UPDATE or DELETE statements. "
#~ "Hibernate is a <emphasis>state management service, you do not "
#~ "have to think in <emphasis>statements to use it. JDBC is a "
#~ "perfect API for executing SQL statements, you can get a JDBC "
#~ "<literal>Connection at any time by calling session."
#~ "connection()</literal>. Furthermore, the notion of mass operations "
#~ "conflicts with object/relational mapping for online transaction "
#~ "processing-oriented applications. Future versions of Hibernate can, "
#~ "however, provide special mass operation functions. See <xref linkend="
#~ "\"batch\"/> for some possible batch operation tricks."
#~ msgstr ""
#~ "请注意 Hibernate 本身不提供直接执行 <literal>UPDATE 或 "
#~ "<literal>DELETE 语句的 API。Hibernate 提供的是 state "
#~ "management</emphasis> 服务,你不必考虑要使用的 statements 你都可以得到一个 "
#~ "<literal>Connection 对象。 此外,在联机事务处理(OLTP)程序中,"
#~ "大量操作(mass operations)与对象/关系映射的观点是相冲突的。Hibernate 的将"
#~ "来版本可能会提供专门的进行大量操作(mass operation)的功能。参考 <xref "
#~ "linkend=\"batch\"/>,寻找一些可用的批量(batch)操作技巧。"

#~ msgid ""
#~ "A special cascade style, <literal>delete-orphan, applies only "
#~ "to one-to-many associations, and indicates that the <literal>delete()delete() 操作"
#~ "应该被应用于所有从关联中删除的对象。"

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate session_api.po source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.