|
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.
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 " for="" more="" information."="" msgstr="" ""="" "如果希望相关è”的脱管对象(通过引用“å¯åˆ°è¾¾â€çš„脱管对象)的数æ®ä¹Ÿè¦æ›´æ–°åˆ°æ•°æ®åº“"="" "时(并且也<emphasis>ä»…ä»…<="" emphasis="">在这ç§æƒ…况),å¯ä»¥å¯¹è¯¥ç›¸å…³è”的脱管对象å•ç‹¬"
"调用 <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:
|