|
Hibernate example source code file (tutorial.po)
This example Hibernate source code file (tutorial.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 tutorial.po source code
# translation of tutorial.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: tutorial\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-20 21:02+0000\n"
"PO-Revision-Date: 2010-03-16 09:56+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
#: tutorial.xml:34
#, no-c-format
msgid "Tutorial"
msgstr "教程"
#. Tag: para
#: tutorial.xml:36
#, no-c-format
msgid ""
"Intended for new users, this chapter provides an step-by-step introduction "
"to Hibernate, starting with a simple application using an in-memory "
"database. The tutorial is based on an earlier tutorial developed by Michael "
"Gloegl. All code is contained in the <filename>tutorials/web "
"directory of the project source."
msgstr ""
"é¢å‘新用户,从一个简å•çš„使用内å˜æ•°æ®åº“的例åå¼€å§‹ï¼Œæœ¬ç« æ供对 Hibernate çš„é€æ¥"
"介ç»ã€‚本教程基于 Michael Gloegl 早期编写的手册。所有代ç 都包å«åœ¨ "
"<filename>tutorials/web 目录下。"
#. Tag: para
#: tutorial.xml:45
#, no-c-format
msgid ""
"This tutorial expects the user have knowledge of both Java and SQL. If you "
"have a limited knowledge of JAVA or SQL, it is advised that you start with a "
"good introduction to that technology prior to attempting to learn Hibernate."
msgstr ""
"本教程期望用户具备 Java å’Œ SQL çŸ¥è¯†ã€‚å¦‚æžœä½ è¿™æ–¹é¢çš„知识有é™ï¼Œæˆ‘ä»¬å»ºè®®ä½ åœ¨å¦"
"ä¹ Hibernate 之å‰å…ˆå¥½å¥½äº†è§£è¿™äº›æŠ€æœ¯ã€‚"
#. Tag: para
#: tutorial.xml:54
#, no-c-format
msgid ""
"The distribution contains another example application under the "
"<filename>tutorial/eg project source directory."
msgstr ""
"本版本在æºä»£ç 目录 <filename>tutorial/eg 下还包å«å¦å¤–一个例程。"
#. Tag: title
#: tutorial.xml:62
#, no-c-format
msgid "Part 1 - The first Hibernate Application"
msgstr "第一部分 ï¼ ç¬¬ä¸€ä¸ª Hibernate 应用程åº"
#. Tag: para
#: tutorial.xml:64
#, no-c-format
msgid ""
"For this example, we will set up a small database application that can store "
"events we want to attend and information about the host(s) of these events."
msgstr ""
"在这个例å里,我们将设立一个å°åº”用程åºå¯ä»¥ä¿å˜æˆ‘们希望å‚åŠ çš„æ´»åŠ¨ï¼ˆevents)和"
"这些活动主办方的相关信æ¯ã€‚(译者注:在本教程的åŽé¢éƒ¨åˆ†ï¼Œæˆ‘们将直接使用 event "
"而ä¸æ˜¯å®ƒçš„ä¸æ–‡ç¿»è¯‘“活动â€ï¼Œä»¥å…混淆。)"
#. Tag: para
#: tutorial.xml:70
#, no-c-format
msgid ""
"Although you can use whatever database you feel comfortable using, we will "
"use <ulink url=\"http://hsqldb.org/\">HSQLDB (an in-memory, Java "
"database) to avoid describing installation/setup of any particular database "
"servers."
msgstr ""
"è™½ç„¶ä½ å¯ä»¥ä½¿ç”¨ä»»ä½•æ•°æ®åº“,我们还是用 <ulink url=\"http://hsqldb.org/"
"\">HSQLDB</ulink>(一个用 Java 编写的内å˜æ•°æ®åº“)æ¥é¿å…èŠ±è´¹ç¯‡ç« å¯¹æ•°æ®åº“æœåŠ¡å™¨"
"的安装/é…置进行解释。"
#. Tag: title
#: tutorial.xml:79
#, no-c-format
msgid "Setup"
msgstr "设置"
#. Tag: para
#: tutorial.xml:81
#, no-c-format
msgid ""
"The first thing we need to do is to set up the development environment. We "
"will be using the \"standard layout\" advocated by alot of build tools such "
"as <ulink url=\"http://maven.org\">Maven. Maven, in particular, has "
"a good resource describing this <ulink url=\"http://maven.apache.org/guides/"
"introduction/introduction-to-the-standard-directory-layout.html\">layout</"
"ulink>. As this tutorial is to be a web application, we will be creating and "
"making use of <filename>src/main/java, src/main/"
"resources</filename> and src/main/webapp directories."
msgstr ""
"我们需è¦åšçš„第一件事情是设置开å‘环境。我们将使用许多构建工具如 <ulink url="
"\"http://maven.org\">Maven</ulink> 所鼓å¹çš„â€œæ ‡å‡†æ ¼å¼â€ã€‚特别是 Maven,它的资æº"
"对这个<ulink url=\"http://maven.apache.org/guides/introduction/introduction-"
"to-the-standard-directory-layout.html\">æ ¼å¼ï¼ˆlayout)</ulink>有ç€å¾ˆå¥½çš„æ"
"è¿°ã€‚å› ä¸ºæœ¬æ•™ç¨‹ä½¿ç”¨çš„æ˜¯ web 应用程åºï¼Œæˆ‘么将创建和使用 <filename>src/main/"
"java</filename>ã€src/main/resources å’Œ src/"
"main/webapp</filename> 目录。"
#. Tag: para
#: tutorial.xml:91
#, no-c-format
msgid ""
"We will be using Maven in this tutorial, taking advantage of its transitive "
"dependency management capabilities as well as the ability of many IDEs to "
"automatically set up a project for us based on the maven descriptor."
msgstr ""
"在本教程里我们将使用 Maven,利用其 transitive dependency 管ç†ä»¥åŠæ ¹æ® Maven "
"æ述符用 IDE 自动设置项目的能力。"
#. Tag: programlisting
#: tutorial.xml:97
#, no-c-format
msgid ""
"<![CDATA[\n"
"\n"
" <groupId>org.hibernate.tutorials\n"
" <artifactId>hibernate-tutorial\n"
" <version>1.0.0-SNAPSHOT\n"
" <name>First Hibernate Tutorial\n"
"\n"
" <build>\n"
" <!-- we dont want the version to be part of the generated war file "
"name -->\n"
" <finalName>${artifactId}\n"
" </build>\n"
"\n"
" <dependencies>\n"
" <dependency>\n"
" <groupId>org.hibernate\n"
" <artifactId>hibernate-core\n"
" </dependency>\n"
"\n"
" <!-- Because this is a web app, we also have a dependency on the "
"servlet api. -->\n"
" <dependency>\n"
" <groupId>javax.servlet\n"
" <artifactId>servlet-api\n"
" </dependency>\n"
"\n"
" <!-- Hibernate uses slf4j for logging, for our purposes here use the "
"simple backend -->\n"
" <dependency>\n"
" <groupId>org.slf4j\n"
" <artifactId>slf4j-simple\n"
" </dependency>\n"
"\n"
" <!-- Hibernate gives you a choice of bytecode providers between "
"cglib and javassist -->\n"
" <dependency>\n"
" <groupId>javassist\n"
" <artifactId>javassist\n"
" </dependency>\n"
" </dependencies>\n"
"\n"
"</project>]]>"
msgstr ""
"<![CDATA[\n"
"\n"
" <groupId>org.hibernate.tutorials\n"
" <artifactId>hibernate-tutorial\n"
" <version>1.0.0-SNAPSHOT\n"
" <name>First Hibernate Tutorial\n"
"\n"
" <build>\n"
" <!-- we dont want the version to be part of the generated war file "
"name -->\n"
" <finalName>${artifactId}\n"
" </build>\n"
"\n"
" <dependencies>\n"
" <dependency>\n"
" <groupId>org.hibernate\n"
" <artifactId>hibernate-core\n"
" </dependency>\n"
"\n"
" <!-- Because this is a web app, we also have a dependency on the "
"servlet api. -->\n"
" <dependency>\n"
" <groupId>javax.servlet\n"
" <artifactId>servlet-api\n"
" </dependency>\n"
"\n"
" <!-- Hibernate uses slf4j for logging, for our purposes here use the "
"simple backend -->\n"
" <dependency>\n"
" <groupId>org.slf4j\n"
" <artifactId>slf4j-simple\n"
" </dependency>\n"
"\n"
" <!-- Hibernate gives you a choice of bytecode providers between "
"cglib and javassist -->\n"
" <dependency>\n"
" <groupId>javassist\n"
" <artifactId>javassist\n"
" </dependency>\n"
" </dependencies>\n"
"\n"
"</project>]]>"
#. Tag: para
#: tutorial.xml:100
#, fuzzy, no-c-format
msgid ""
"It is not a requirement to use Maven. If you wish to use something else to "
"build this tutorial (such as Ant), the layout will remain the same. The only "
"change is that you will need to manually account for all the needed "
"dependencies. If you use something like <ulink url=\"http://ant.apache.org/"
"ivy/\">Ivy</ulink> providing transitive dependency management you would "
"still use the dependencies mentioned below. Otherwise, you'd need to grab "
"<emphasis>all dependencies, both explicit and transitive, and add "
"them to the project's classpath. If working from the Hibernate distribution "
"bundle, this would mean <filename>hibernate3.jar, all artifacts "
"in the <filename>lib/required directory and all files from either "
"the <filename>lib/bytecode/cglib or lib/bytecode/"
"javassist</filename> directory; additionally you will need both the servlet-"
"api jar and one of the slf4j logging backends."
msgstr ""
"Maven 并ä¸è¦æ±‚è¿™æ ·ã€‚å¦‚æžœä½ å¸Œæœ›ä½¿ç”¨å…¶ä»–æŠ€æœ¯æ¥æž„建这个教程(如 Antï¼‰ï¼Œæ ¼å¼å°†ä¿"
"æŒä¸å˜ã€‚唯一的改å˜æ˜¯ä½ 将需è¦æ‰‹å·¥ç®¡ç†æ‰€æœ‰çš„ä¾èµ–å…³ç³»ã€‚å¦‚æžœä½ ä½¿ç”¨ <ulink url="
"\"http://ant.apache.org/ivy/\">Ivy</ulink> æ¥æä¾› transitive dependency 管"
"ç†ï¼Œä½ å°†ä»ç„¶ä¸‹é¢æ到的ä¾èµ–关系。å¦åˆ™ï¼Œä½ 将需è¦æ‰¾åˆ°æ‰€æœ‰çš„ä¾èµ–关系(显性的和过"
"æ¸¡çš„ï¼‰å¹¶æŠŠå®ƒä»¬æ·»åŠ åˆ°é¡¹ç›®çš„ classpath 里。如果使用 Hibernate æ†ç»‘版本,这æ„味"
"ç€ <filename>hibernate3.jarã€lib/required ç›®"
"录下的所有 artifact 和 <filename>lib/bytecode/cglib 或 "
"<filename>lib/bytecode/javassist 下的所有文件,æ¤å¤–ä½ å°†éœ€è¦ "
"servlet-api jar 和一个 slf4j 日志åŽå°æ–‡ä»¶ã€‚ "
#. Tag: para
#: tutorial.xml:117
#, no-c-format
msgid ""
"Save this file as <filename>pom.xml in the project root directory."
msgstr "把这个文件ä¿å˜ä¸ºé¡¹ç›®æ ¹ç›®å½•ä¸‹çš„ <filename>pom.xml。"
#. Tag: title
#: tutorial.xml:124
#, no-c-format
msgid "The first class"
msgstr "第一个 class"
#. Tag: para
#: tutorial.xml:126
#, no-c-format
msgid ""
"Next, we create a class that represents the event we want to store in the "
"database; it is a simple JavaBean class with some properties:"
msgstr ""
"接下æ¥æˆ‘们创建一个类,用æ¥ä»£è¡¨é‚£äº›æˆ‘们希望储å˜åœ¨æ•°æ®åº“里的 event,这是一个具"
"æœ‰ä¸€äº›å±žæ€§çš„ç®€å• JavaBean 类:"
#. Tag: programlisting
#: tutorial.xml:131
#, no-c-format
msgid ""
"<![CDATA[package org.hibernate.tutorial.domain;\n"
"\n"
"import java.util.Date;\n"
"\n"
"public class Event {\n"
" private Long id;\n"
"\n"
" private String title;\n"
" private Date date;\n"
"\n"
" public Event() {}\n"
"\n"
" public Long getId() {\n"
" return id;\n"
" }\n"
"\n"
" private void setId(Long id) {\n"
" this.id = id;\n"
" }\n"
"\n"
" public Date getDate() {\n"
" return date;\n"
" }\n"
"\n"
" public void setDate(Date date) {\n"
" this.date = date;\n"
" }\n"
"\n"
" public String getTitle() {\n"
" return title;\n"
" }\n"
"\n"
" public void setTitle(String title) {\n"
" this.title = title;\n"
" }\n"
"}]]>"
msgstr ""
"<![CDATA[package org.hibernate.tutorial.domain;\n"
"\n"
"import java.util.Date;\n"
"\n"
"public class Event {\n"
" private Long id;\n"
"\n"
" private String title;\n"
" private Date date;\n"
"\n"
" public Event() {}\n"
"\n"
" public Long getId() {\n"
" return id;\n"
" }\n"
"\n"
" private void setId(Long id) {\n"
" this.id = id;\n"
" }\n"
"\n"
" public Date getDate() {\n"
" return date;\n"
" }\n"
"\n"
" public void setDate(Date date) {\n"
" this.date = date;\n"
" }\n"
"\n"
" public String getTitle() {\n"
" return title;\n"
" }\n"
"\n"
" public void setTitle(String title) {\n"
" this.title = title;\n"
" }\n"
"}]]>"
#. Tag: para
#: tutorial.xml:133
#, no-c-format
msgid ""
"This class uses standard JavaBean naming conventions for property getter and "
"setter methods, as well as private visibility for the fields. Although this "
"is the recommended design, it is not required. Hibernate can also access "
"fields directly, the benefit of accessor methods is robustness for "
"refactoring."
msgstr ""
"ä½ å¯ä»¥çœ‹åˆ°è¿™ä¸ªç±»å¯¹å±žæ€§çš„å˜å–方法(getter and setter methodï¼‰ä½¿ç”¨äº†æ ‡å‡† "
"JavaBean 命å约定,åŒæ—¶æŠŠç±»å±žæ€§ï¼ˆfield)的访问级别设æˆç§æœ‰çš„(private)。这是"
"推è的设计,但并ä¸æ˜¯å¿…须的。Hibernate 也å¯ä»¥ç›´æŽ¥è®¿é—®è¿™äº› field,而使用访问方"
"法(accessor method)的好处是æ供了é‡æž„时的å¥å£®æ€§ï¼ˆrobustness)。"
#. Tag: para
#: tutorial.xml:141
#, no-c-format
msgid ""
"The <literal>id property holds a unique identifier value for a "
"particular event. All persistent entity classes (there are less important "
"dependent classes as well) will need such an identifier property if we want "
"to use the full feature set of Hibernate. In fact, most applications, "
"especially web applications, need to distinguish objects by identifier, so "
"you should consider this a feature rather than a limitation. However, we "
"usually do not manipulate the identity of an object, hence the setter method "
"should be private. Only Hibernate will assign identifiers when an object is "
"saved. Hibernate can access public, private, and protected accessor methods, "
"as well as public, private and protected fields directly. The choice is up "
"to you and you can match it to fit your application design."
msgstr ""
"对一特定的 event, <literal>id 属性æŒæœ‰å”¯ä¸€çš„æ ‡è¯†ç¬¦ï¼ˆidentifier)的"
"值。如果我们希望使用 Hibernate æ供的所有特性,那么所有的æŒä¹…化实体"
"(persistent entity)类(这里也包括一些次è¦ä¾èµ–类)都需è¦ä¸€ä¸ªè¿™æ ·çš„æ ‡è¯†ç¬¦å±ž"
"性。而事实上,大多数应用程åºï¼ˆç‰¹åˆ«æ˜¯ web 应用程åºï¼‰éƒ½éœ€è¦é€šè¿‡æ ‡è¯†ç¬¦æ¥åŒºåˆ«å¯¹"
"è±¡ï¼Œæ‰€ä»¥ä½ åº”è¯¥è€ƒè™‘ä½¿ç”¨æ ‡è¯†ç¬¦å±žæ€§è€Œä¸æ˜¯æŠŠå®ƒå½“作一ç§é™åˆ¶ã€‚然而,我们通常ä¸ä¼šæ“"
"ä½œå¯¹è±¡çš„æ ‡è¯†ï¼ˆidentityï¼‰ï¼Œå› æ¤å®ƒçš„ setter 方法的访问级别应该声明 private。这"
"æ ·å½“å¯¹è±¡è¢«ä¿å˜çš„时候,åªæœ‰ Hibernate å¯ä»¥ä¸ºå®ƒåˆ†é…æ ‡è¯†ç¬¦å€¼ã€‚ä½ å¯çœ‹åˆ°Hibernate"
"å¯ä»¥ç›´æŽ¥è®¿é—® public,private å’Œ protected 的访问方法和 field。所以选择哪ç§æ–¹"
"å¼å®Œå…¨å–å†³äºŽä½ ï¼Œä½ å¯ä»¥ä½¿ä½ çš„é€‰æ‹©ä¸Žä½ çš„åº”ç”¨ç¨‹åºè®¾è®¡ç›¸å»åˆã€‚ "
#. Tag: para
#: tutorial.xml:156
#, no-c-format
msgid ""
"The no-argument constructor is a requirement for all persistent classes; "
"Hibernate has to create objects for you, using Java Reflection. The "
"constructor can be private, however package or public visibility is required "
"for runtime proxy generation and efficient data retrieval without bytecode "
"instrumentation."
msgstr ""
"所有的æŒä¹…化类(persistent classes)都è¦æ±‚æœ‰æ— å‚çš„æž„é€ å™¨ï¼Œå› ä¸º Hibernate å¿…é¡»"
"使用 Java å射机制æ¥ä¸ºä½ åˆ›å»ºå¯¹è±¡ã€‚æž„é€ å™¨ï¼ˆconstructor)的访问级别å¯ä»¥æ˜¯ "
"private,然而当生æˆè¿è¡Œæ—¶ä»£ç†ï¼ˆruntime proxy)的时候则è¦æ±‚使用至少是 package "
"çº§åˆ«çš„è®¿é—®æŽ§åˆ¶ï¼Œè¿™æ ·åœ¨æ²¡æœ‰å—节ç 指令(bytecode instrumentation)的情况下,从"
"æŒä¹…化类里获å–æ•°æ®ä¼šæ›´æœ‰æ•ˆçŽ‡ã€‚ "
#. Tag: para
#: tutorial.xml:164
#, no-c-format
msgid ""
"Save this file to the <filename>src/main/java/org/hibernate/tutorial/domain"
msgstr ""
"<![CDATA["
#. Tag: para
#: tutorial.xml:187
#, no-c-format
msgid ""
"Hibernate DTD is sophisticated. You can use it for auto-completion of XML "
"mapping elements and attributes in your editor or IDE. Opening up the DTD "
"file in your text editor is the easiest way to get an overview of all "
"elements and attributes, and to view the defaults, as well as some comments. "
"Hibernate will not load the DTD file from the web, but first look it up from "
"the classpath of the application. The DTD file is included in "
"<filename>hibernate-core.jar (it is also included in the "
"<filename>hibernate3.jar, if using the distribution bundle)."
msgstr ""
"æ³¨æ„ Hibernate çš„ DTD 是éžå¸¸å¤æ‚çš„ã€‚ä½ çš„ç¼–è¾‘å™¨æˆ–è€… IDE 里使用它æ¥è‡ªåŠ¨å®Œæˆé‚£äº›"
"用æ¥æ˜ å°„çš„ XML å…ƒç´ ï¼ˆelement)和属性(attributeï¼‰ã€‚ä½ ä¹Ÿå¯ä»¥åœ¨æ–‡æœ¬ç¼–辑器里打"
"å¼€ DTD — 这是最简å•çš„æ–¹å¼æ¥æ¦‚è§ˆæ‰€æœ‰çš„å…ƒç´ å’Œ attribute,并查看它们的缺çœå€¼ä»¥åŠ"
"æ³¨é‡Šã€‚æ³¨æ„ Hibernate ä¸ä¼šä»Ž web åŠ è½½ DTD 文件,但它会首先在应用程åºçš„ "
"classpath ä¸æŸ¥æ‰¾ã€‚DTD 文件已包括在 <literal>hibernate3.jar 里,åŒæ—¶"
"也在 Hibernate å‘布包的 <literal>src/ 目录下。 "
#. Tag: para
#: tutorial.xml:200
#, no-c-format
msgid ""
"We will omit the DTD declaration in future examples to shorten the code. It "
"is, of course, not optional."
msgstr ""
"为缩çŸä»£ç 长度,在以åŽçš„例å里我们会çœç•¥ DTD 的声明。当然,在实际的应用程åº"
"ä¸ï¼ŒDTD 声明是必需的。 "
#. Tag: para
#: tutorial.xml:206
#, no-c-format
msgid ""
"Between the two <literal>hibernate-mapping tags, include a "
"<literal>class element. All persistent entity classes (again, "
"there might be dependent classes later on, which are not first-class "
"entities) need a mapping to a table in the SQL database:"
msgstr ""
"在 <literal>hibernate-mapping æ ‡ç¾ï¼ˆtag)之间, å«æœ‰ä¸€ä¸ª "
"<literal>class å…ƒç´ ã€‚æ‰€æœ‰çš„æŒä¹…化实体类(å†æ¬¡å£°æ˜Žï¼Œæˆ–许接下æ¥ä¼šæœ‰ä¾"
"赖类,就是那些次è¦çš„实体)都需è¦ä¸€ä¸ªè¿™æ ·çš„æ˜ å°„ï¼Œæ¥æŠŠç±»å¯¹è±¡æ˜ 射到 SQL æ•°æ®åº“里"
"的表:"
#. Tag: programlisting
#: tutorial.xml:213
#, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<![CDATA["
#. Tag: para
#: tutorial.xml:215
#, no-c-format
msgid ""
"So far we have told Hibernate how to persist and load object of class "
"<literal>Event to the table EVENTS. Each "
"instance is now represented by a row in that table. Now we can continue by "
"mapping the unique identifier property to the tables primary key. As we do "
"not want to care about handling this identifier, we configure Hibernate's "
"identifier generation strategy for a surrogate primary key column:"
msgstr ""
"到目å‰ä¸ºæ¢ï¼Œæˆ‘们告诉了 Hibernate æ€Žæ ·æŠŠ <literal>Events 类的对象æŒ"
"久化到数æ®åº“çš„ <literal>EVENTS 表里,以åŠæ€Žæ ·ä»Ž EVENTSEvents 类的对象。æ¯ä¸ªå®žä¾‹å¯¹åº”ç€æ•°æ®åº“表"
"ä¸çš„一行。现在我们将继ç»è®¨è®ºæœ‰å…³å”¯ä¸€æ ‡è¯†ç¬¦å±žæ€§åˆ°æ•°æ®åº“è¡¨çš„æ˜ å°„ã€‚å¦å¤–,由于我"
"们ä¸å…³å¿ƒæ€Žæ ·å¤„ç†è¿™ä¸ªæ ‡è¯†ç¬¦ï¼Œæˆ‘们就é…置由 Hibernate çš„æ ‡è¯†ç¬¦ç”Ÿæˆç–ç•¥æ¥äº§ç”Ÿä»£ç†"
"主键å—段:"
#. Tag: programlisting
#: tutorial.xml:225
#, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<![CDATA["
#. Tag: para
#: tutorial.xml:227
#, no-c-format
msgid ""
"The <literal>id element is the declaration of the identifier "
"property. The <literal>name=\"id\" mapping attribute declares the "
"name of the JavaBean property and tells Hibernate to use the <literal>getId()"
"</literal> and setId() methods to access the property. "
"The column attribute tells Hibernate which column of the <literal>EVENTS å…ƒç´ æ˜¯å¯¹ identifier 属性的声明。name=\"id\" å’Œ setId() 方法æ¥è®¿é—®è¿™ä¸ªå±žæ€§ã€‚"
"column 属性告诉 Hibernate <literal>EVENTS 表的哪个å—段æŒæœ‰ä¸»é”®å€¼ã€‚"
#. Tag: para
#: tutorial.xml:237
#, no-c-format
msgid ""
"The nested <literal>generator element specifies the identifier "
"generation strategy (aka how are identifier values generated?). In this case "
"we choose <literal>native, which offers a level of portability "
"depending on the configured database dialect. Hibernate supports database "
"generated, globally unique, as well as application assigned, identifiers. "
"Identifier value generation is also one of Hibernate's many extension points "
"and you can plugin in your own strategy."
msgstr ""
"嵌套的 <literal>generator å…ƒç´ æŒ‡å®šæ ‡è¯†ç¬¦çš„ç”Ÿæˆç–ç•¥ï¼ˆä¹Ÿå°±æ˜¯æ ‡è¯†ç¬¦å€¼"
"是怎么产生的)。在这个例å里,我们选择 <literal>native,它æ供了å–"
"决于数æ®åº“方言的å¯ç§»æ¤æ€§ã€‚Hibernate æ•°æ®åº“生æˆçš„ã€å…¨å±€æ€§å”¯ä¸€çš„以åŠåº”用程åºåˆ†"
"é…çš„æ ‡è¯†ç¬¦ã€‚æ ‡è¯†ç¬¦å€¼çš„ç”Ÿæˆä¹Ÿæ˜¯ Hibernate çš„æ‰©å±•åŠŸèƒ½ä¹‹ä¸€ï¼Œä½ å¯ä»¥æ’入自己的ç–"
"略。"
#. Tag: para
#: tutorial.xml:249
#, fuzzy, no-c-format
msgid ""
"<literal>native is no longer consider the best strategy in terms "
"of portability. for further discussion, see"
msgstr ""
"从移æ¤æ€§æ¥è¯´ï¼Œ<literal>native ä¸å†è¢«è®¤ä¸ºæ˜¯æœ€å¥½çš„ç–略。进一æ¥çš„讨"
"论,请å‚考 <xref linkend=\"portability-idgen\" />。 "
#. Tag: para
#: tutorial.xml:255
#, no-c-format
msgid ""
"Lastly, we need to tell Hibernate about the remaining entity class "
"properties. By default, no properties of the class are considered persistent:"
msgstr ""
"最åŽæˆ‘ä»¬åœ¨æ˜ å°„æ–‡ä»¶é‡Œé¢åŒ…å«éœ€è¦æŒä¹…化属性的声明。默认情况下,类里é¢çš„属性都被"
"视为éžæŒä¹…化的: "
#. Tag: programlisting
#: tutorial.xml:261
#, no-c-format
msgid ""
"<![CDATA[\n"
"<hibernate-mapping package=\"org.hibernate.tutorial.domain\">\n"
"\n"
" <class name=\"Event\" table=\"EVENTS\">\n"
" <id name=\"id\" column=\"EVENT_ID\">\n"
" <generator class=\"native\"/>\n"
" </id>\n"
" <property name=\"date\" type=\"timestamp\" column=\"EVENT_DATE\"/>\n"
" <property name=\"title\"/>\n"
" </class>\n"
"\n"
"</hibernate-mapping>]]>"
msgstr ""
"<![CDATA[\n"
"<hibernate-mapping package=\"org.hibernate.tutorial.domain\">\n"
"\n"
" <class name=\"Event\" table=\"EVENTS\">\n"
" <id name=\"id\" column=\"EVENT_ID\">\n"
" <generator class=\"native\"/>\n"
" </id>\n"
" <property name=\"date\" type=\"timestamp\" column=\"EVENT_DATE\"/>\n"
" <property name=\"title\"/>\n"
" </class>\n"
"\n"
"</hibernate-mapping>]]>"
#. Tag: para
#: tutorial.xml:263
#, no-c-format
msgid ""
"Similar to the <literal>id element, the name "
"attribute of the <literal>property element tells Hibernate which "
"getter and setter methods to use. In this case, Hibernate will search for "
"<literal>getDate(), setDate(), getTitle"
"()</literal> and setTitle() methods."
msgstr ""
"å’Œ <literal>id å…ƒç´ ä¸€æ ·ï¼Œproperty å…ƒç´ çš„ "
"<literal>name 属性告诉 Hibernate 使用哪个 getter 和 setter 方法。在"
"æ¤ä¾‹ä¸ï¼ŒHibernate 会寻找 <literal>getDate()ã€setDate()getTitle() å’Œ setTitle() æ–¹"
"法。 "
#. Tag: para
#: tutorial.xml:274
#, no-c-format
msgid ""
"Why does the <literal>date property mapping include the "
"<literal>column attribute, but the title does "
"not? Without the <literal>column attribute, Hibernate by default "
"uses the property name as the column name. This works for <literal>titledate is a reserved keyword in most "
"databases so you will need to map it to a different name."
msgstr ""
"为什么 <literal>date å±žæ€§çš„æ˜ å°„å«æœ‰ column "
"attribute,而 <literal>title å´æ²¡æœ‰ï¼Ÿå½“没有设定 columnï¼Œè¿™æ ·å·¥ä½œå¾—å¾ˆå¥½ã€‚ç„¶è€Œï¼Œdate "
"在多数的数æ®åº“里,是一个ä¿ç•™å…³é”®å—ï¼Œæ‰€ä»¥æˆ‘ä»¬æœ€å¥½æŠŠå®ƒæ˜ å°„æˆä¸€ä¸ªä¸åŒçš„åå—。 "
#. Tag: para
#: tutorial.xml:284
#, no-c-format
msgid ""
"The <literal>title mapping also lacks a type "
"attribute. The types declared and used in the mapping files are not Java "
"data types; they are not SQL database types either. These types are called "
"<emphasis>Hibernate mapping types, converters which can translate "
"from Java to SQL data types and vice versa. Again, Hibernate will try to "
"determine the correct conversion and mapping type itself if the "
"<literal>type attribute is not present in the mapping. In some "
"cases this automatic detection using Reflection on the Java class might not "
"have the default you expect or need. This is the case with the "
"<literal>date property. Hibernate cannot know if the property, "
"which is of <literal>java.util.Date, should map to a SQL "
"<literal>date, timestamp, or time converter."
msgstr ""
"å¦ä¸€æœ‰è¶£çš„事情是 <literal>title 属性缺少一个 type,它们能把 Java æ•°æ®"
"类型转æ¢åˆ° SQL æ•°æ®ç±»åž‹ï¼Œå之亦然。å†æ¬¡é‡ç”³ï¼Œå¦‚æžœåœ¨æ˜ å°„æ–‡ä»¶ä¸æ²¡æœ‰è®¾ç½® "
"<literal>type 属性的è¯ï¼ŒHibernate 会自己试ç€åŽ»ç¡®å®šæ£ç¡®çš„转æ¢ç±»åž‹å’Œ"
"å®ƒçš„æ˜ å°„ç±»åž‹ã€‚åœ¨æŸäº›æƒ…况下这个自动检测机制(在 Java 类上使用å射机制)ä¸ä¼šäº§"
"ç”Ÿä½ æ‰€æœŸå¾…æˆ–éœ€è¦çš„缺çœå€¼ã€‚<literal>date 属性就是个很好的例å,"
"Hibernate æ— æ³•çŸ¥é“这个属性(<literal>java.util.Date 类型的)应该被"
"æ˜ å°„æˆï¼šSQL <literal>date,或 timestamp,还是 "
"<literal>time å—段。在æ¤ä¾‹ä¸ï¼ŒæŠŠè¿™ä¸ªå±žæ€§æ˜ å°„æˆ timestamp 目录 ï¼ è¿™æ˜¯ HSQL DB å˜å‚¨æ•°"
"æ®æ–‡ä»¶çš„地方。æ¤æ—¶åœ¨ data 目录ä¸è¿è¡Œ <literal>java -classpath ../lib/hsqldb."
"jar org.hsqldb.Server</literal> å°±å¯å¯åŠ¨æ•°æ®åº“ã€‚ä½ å¯ä»¥åœ¨ log ä¸çœ‹åˆ°å®ƒçš„å¯åŠ¨ï¼Œ"
"åŠç»‘定到 TCP/IP 套接å—,这æ£æ˜¯æˆ‘们的应用程åºç¨åŽä¼šè¿žæŽ¥çš„åœ°æ–¹ã€‚å¦‚æžœä½ å¸Œæœ›åœ¨æœ¬"
"例ä¸è¿è¡Œä¸€ä¸ªå…¨æ–°çš„æ•°æ®åº“,就在窗å£ä¸æŒ‰ä¸‹ <literal>CTRL + C æ¥å…³é— "
"HSQL æ•°æ®åº“ï¼Œå¹¶åˆ é™¤ <literal>data/ 目录下的所有文件,å†é‡æ–°å¯åŠ¨ "
"HSQL æ•°æ®åº“。 "
#. Tag: para
#: tutorial.xml:340
#, no-c-format
msgid ""
"Hibernate will be connecting to the database on behalf of your application, "
"so it needs to know how to obtain connections. For this tutorial we will be "
"using a standalone connection pool (as opposed to a <interfacename>javax.sql."
"DataSource</interfacename>). Hibernate comes with support for two third-"
"party open source JDBC connection pools: <ulink url=\"https://sourceforge."
"net/projects/c3p0\">c3p0</ulink> and . However, we will be using the Hibernate built-in "
"connection pool for this tutorial."
msgstr ""
"Hibernate å°†ä¸ºä½ çš„åº”ç”¨ç¨‹åºè¿žæŽ¥åˆ°æ•°æ®åº“,所以它需è¦çŸ¥é“如何获å–连接。在这个教"
"ç¨‹é‡Œï¼Œæˆ‘ä»¬ä½¿ç”¨ä¸€ä¸ªç‹¬ç«‹è¿žæŽ¥æ± ï¼ˆå’Œ <interfacename>javax.sql.DataSource å’Œ 。然而,在本教程里我们将使"
"用 Hibernate å†…ç½®çš„è¿žæŽ¥æ± ã€‚"
#. Tag: para
#: tutorial.xml:351
#, no-c-format
msgid ""
"The built-in Hibernate connection pool is in no way intended for production "
"use. It lacks several features found on any decent connection pool."
msgstr "嵌入的 Hibernate è¿žæŽ¥æ± ä¸ç”¨äºŽäº§å“环境。它缺ä¹è¿žæŽ¥æ± é‡Œçš„å‡ ä¸ªåŠŸèƒ½ã€‚"
#. Tag: para
#: tutorial.xml:357
#, no-c-format
msgid ""
"For Hibernate's configuration, we can use a simple <literal>hibernate."
"properties</literal> file, a more sophisticated hibernate.cfg.xmlhibernate.cfg.xml\n"
" <property name=\"connection.password\">\n"
"\n"
" <!-- JDBC connection pool (use the built-in) -->\n"
" <property name=\"connection.pool_size\">1\n"
"\n"
" <!-- SQL dialect -->\n"
" <property name=\"dialect\">org.hibernate.dialect.HSQLDialect\n"
"\n"
" <!-- Disable the second-level cache -->\n"
" <property name=\"cache.provider_class\">org.hibernate.cache."
"NoCacheProvider</property>\n"
"\n"
" <!-- Echo all executed SQL to stdout -->\n"
" <property name=\"show_sql\">true\n"
"\n"
" <!-- Drop and re-create the database schema on startup -->\n"
" <property name=\"hbm2ddl.auto\">update\n"
"\n"
" <mapping resource=\"org/hibernate/tutorial/domain/Event.hbm.xml\"/>\n"
"\n"
" </session-factory>\n"
"\n"
"</hibernate-configuration>]]>"
msgstr ""
"<![CDATA[\n"
" <property name=\"connection.password\">\n"
"\n"
" <!-- JDBC connection pool (use the built-in) -->\n"
" <property name=\"connection.pool_size\">1\n"
"\n"
" <!-- SQL dialect -->\n"
" <property name=\"dialect\">org.hibernate.dialect.HSQLDialect\n"
"\n"
" <!-- Disable the second-level cache -->\n"
" <property name=\"cache.provider_class\">org.hibernate.cache."
"NoCacheProvider</property>\n"
"\n"
" <!-- Echo all executed SQL to stdout -->\n"
" <property name=\"show_sql\">true\n"
"\n"
" <!-- Drop and re-create the database schema on startup -->\n"
" <property name=\"hbm2ddl.auto\">update\n"
"\n"
" <mapping resource=\"org/hibernate/tutorial/domain/Event.hbm.xml\"/>\n"
"\n"
" </session-factory>\n"
"\n"
"</hibernate-configuration>]]>"
#. Tag: para
#: tutorial.xml:366
#, no-c-format
msgid "Notice that this configuration file specifies a different DTD"
msgstr "请注æ„,这个é…置文件指定了一个ä¸åŒçš„ DTD。"
#. Tag: para
#: tutorial.xml:369
#, no-c-format
msgid ""
"You configure Hibernate's <literal>SessionFactory. SessionFactory "
"is a global factory responsible for a particular database. If you have "
"several databases, for easier startup you should use several <literal><"
"session-factory></literal> configurations in several configuration files."
msgstr ""
"注æ„这个 XML é…置使用了一个ä¸åŒçš„ DTD。在这里,我们é…置了 Hibernate çš„"
"<literal>SessionFactory — 一个关è”于特定数æ®åº“全局的工厂"
"(factoryï¼‰ã€‚å¦‚æžœä½ è¦ä½¿ç”¨å¤šä¸ªæ•°æ®åº“,就è¦ç”¨å¤šä¸ªçš„ <literal><session-"
"factory></literal>,通常把它们放在多个é…置文件ä¸ï¼ˆä¸ºäº†æ›´å®¹æ˜“å¯åŠ¨ï¼‰ã€‚ "
#. Tag: para
#: tutorial.xml:376
#, no-c-format
msgid ""
"The first four <literal>property elements contain the necessary "
"configuration for the JDBC connection. The dialect <literal>property å…ƒç´ åŒ…å«äº† JDBC 连接所必需的é…置。方言 "
"<literal>property å…ƒç´ æŒ‡å®šäº† Hibernate 生æˆçš„特定 SQL è¯å¥ã€‚"
#. Tag: para
#: tutorial.xml:383
#, fuzzy, no-c-format
msgid ""
"In most cases, Hibernate is able to properly determine which dialect to use. "
"See <xref linkend=\"portability-dialectresolver\"/> for more information."
msgstr ""
"在大多数情况下,Hibernate 都能够æ£ç¡®åœ°å†³å®šæ‰€ä½¿ç”¨çš„方言。更多信æ¯è¯·å‚考 <xref "
"linkend=\"portability-dialectresolver\" />。 "
#. Tag: para
#: tutorial.xml:389
#, no-c-format
msgid ""
"Hibernate's automatic session management for persistence contexts is "
"particularly useful in this context. The <literal>hbm2ddl.auto "
"option turns on automatic generation of database schemas directly into the "
"database. This can also be turned off by removing the configuration option, "
"or redirected to a file with the help of the <literal>SchemaExport "
"Ant task. Finally, add the mapping file(s) for persistent classes to the "
"configuration."
msgstr ""
"最开始的 4 个 <literal>property å…ƒç´ åŒ…å«å¿…è¦çš„ JDBC 连接信æ¯ã€‚方言"
"(dialect)的 <literal>property å…ƒç´ æŒ‡æ˜Ž Hibernate 生æˆçš„特定 SQL "
"å˜é‡ã€‚ä½ å¾ˆå¿«ä¼šçœ‹åˆ°ï¼ŒHibernate 对æŒä¹…化上下文的自动 session 管ç†å°±ä¼šæ´¾ä¸Šç”¨"
"场。 打开 <literal>hbm2ddl.auto 选项将自动生æˆæ•°æ®åº“模å¼ï¼ˆschema)"
"ï¼ ç›´æŽ¥åŠ å…¥æ•°æ®åº“ä¸ã€‚当然这个选项也å¯ä»¥è¢«å…³é—(通过去除这个é…置选项)或者通"
"过 Ant 任务 <literal>SchemaExport 的帮助æ¥æŠŠæ•°æ®åº“ schema é‡å®šå‘到"
"文件ä¸ã€‚最åŽï¼Œåœ¨é…ç½®ä¸ä¸ºæŒä¹…åŒ–ç±»åŠ å…¥æ˜ å°„æ–‡ä»¶ã€‚ "
#. Tag: para
#: tutorial.xml:398
#, no-c-format
msgid ""
"Save this file as <filename>hibernate.cfg.xml into the "
"<filename>src/main/resources directory."
msgstr ""
"把这个文件ä¿å˜ä¸º <filename>src/main/resources 目录下的 "
"<filename>hibernate.cfg.xml。"
#. Tag: title
#: tutorial.xml:406
#, no-c-format
msgid "Building with Maven"
msgstr "用 Maven 构建 "
#. Tag: para
#: tutorial.xml:408
#, no-c-format
msgid ""
"We will now build the tutorial with Maven. You will need to have Maven "
"installed; it is available from the <ulink url=\"http://maven.apache.org/"
"download.html\">Maven download page</ulink>. Maven will read the /"
"pom.xml</filename> file we created earlier and know how to perform some "
"basic project tasks. First, lets run the <literal>compile goal to "
"make sure we can compile everything so far:"
msgstr ""
"我们将用 Maven æž„å»ºè¿™ä¸ªæ•™ç¨‹ã€‚ä½ å°†éœ€è¦å®‰è£… Mavenï¼›ä½ å¯ä»¥ä»Ž <ulink url="
"\"http://maven.apache.org/download.html\">Maven 下载页é¢</ulink>获得 Maven。"
"Maen 将读å–我们先å‰åˆ›å»ºçš„ <filename>/pom.xml 并知é“执行基本的项目"
"任务。首先,让我们è¿è¡Œ <literal>compile ç›®æ ‡æ¥ç¡®ä¿æˆ‘们å¯ä»¥ç¼–译到目"
"å‰ä¸ºæ¢çš„所有程åºï¼š"
#. Tag: programlisting
#: tutorial.xml:418
#, no-c-format
msgid ""
"<![CDATA[[hibernateTutorial]$ mvn compile\n"
"[INFO] Scanning for projects...\n"
"[INFO] "
"------------------------------------------------------------------------\n"
"[INFO] Building First Hibernate Tutorial\n"
"[INFO] task-segment: [compile]\n"
"[INFO] "
"------------------------------------------------------------------------\n"
"[INFO] [resources:resources]\n"
"[INFO] Using default encoding to copy filtered resources.\n"
"[INFO] [compiler:compile]\n"
"[INFO] Compiling 1 source file to /home/steve/projects/sandbox/"
"hibernateTutorial/target/classes\n"
"[INFO] "
"------------------------------------------------------------------------\n"
"[INFO] BUILD SUCCESSFUL\n"
"[INFO] "
"------------------------------------------------------------------------\n"
"[INFO] Total time: 2 seconds\n"
"[INFO] Finished at: Tue Jun 09 12:25:25 CDT 2009\n"
"[INFO] Final Memory: 5M/547M\n"
"[INFO] "
"------------------------------------------------------------------------]]>"
msgstr ""
#. Tag: title
#: tutorial.xml:423
#, no-c-format
msgid "Startup and helpers"
msgstr "å¯åŠ¨å’Œè¾…助类"
#. Tag: para
#: tutorial.xml:425
#, no-c-format
msgid ""
"It is time to load and store some <literal>Event objects, but "
"first you have to complete the setup with some infrastructure code. You have "
"to startup Hibernate by building a global <interfacename>org.hibernate."
"SessionFactory</interfacename> object and storing it somewhere for easy "
"access in application code. A <interfacename>org.hibernate.SessionFactoryorg.hibernate.Sessionorg.hibernate.Session is a thread-safe "
"global object that is instantiated once."
msgstr ""
"是时候æ¥åŠ 载和储å˜ä¸€äº› <literal>Event 对象了,但首先我们得编写一些"
"基础的代ç 以完æˆè®¾ç½®ã€‚我们必须å¯åŠ¨ Hibernate,æ¤è¿‡ç¨‹åŒ…括创建一个全局的 "
"<literal>SessoinFactory,并把它储å˜åœ¨åº”用程åºä»£ç 容易访问的地方。"
"<literal>SessionFactory å¯ä»¥åˆ›å»ºå¹¶æ‰“开新的 SessionSession 代表一个å•çº¿ç¨‹çš„å•å…ƒæ“作,"
"<interfacename>org.hibernate.SessionFactory 则是个线程安全的"
"全局对象,åªéœ€è¦è¢«å®žä¾‹åŒ–一次。 "
#. Tag: para
#: tutorial.xml:439
#, no-c-format
msgid ""
"We will create a <literal>HibernateUtil helper class that takes "
"care of startup and makes accessing the <interfacename>org.hibernate."
"SessionFactory</interfacename> more convenient."
msgstr ""
"我们将创建一个 <literal>HibernateUtil 辅助类(helper class)æ¥è´Ÿè´£"
"å¯åŠ¨ Hibernate 和更方便地æ“作 <interfacename>org.hibernate.SessionFactory "
"reference from JNDI in an application server or any other location for that "
"matter."
msgstr ""
"这个类ä¸ä½†åœ¨å®ƒçš„é™æ€åˆå§‹åŒ–è¿‡ç¨‹ï¼ˆä»…å½“åŠ è½½è¿™ä¸ªç±»çš„æ—¶å€™è¢« JVM 执行一次)ä¸äº§ç”Ÿå…¨"
"局的 <interfacename>org.hibernate.SessionFactory,而且éšè—了"
"它使用了é™æ€ singleton 的事实。它也å¯èƒ½åœ¨åº”用程åºæœåŠ¡å™¨ä¸çš„ JNDI 查找 "
"<interfacename>org.hibernate.SessionFactory。"
#. Tag: para
#: tutorial.xml:461
#, no-c-format
msgid ""
"If you give the <interfacename>org.hibernate.SessionFactory "
"a name in your configuration, Hibernate will try to bind it to JNDI under "
"that name after it has been built. Another, better option is to use a JMX "
"deployment and let the JMX-capable container instantiate and bind a "
"<literal>HibernateService to JNDI. Such advanced options are "
"discussed later."
msgstr ""
"å¦‚æžœä½ åœ¨é…置文件ä¸ç»™ <interfacename>org.hibernate.SessionFactory 并把它绑定到 JNDI。这些高级å¯é€‰é¡¹åœ¨åŽé¢çš„"
"ç« èŠ‚ä¸ä¼šè®¨è®ºåˆ°ã€‚"
#. Tag: para
#: tutorial.xml:470
#, no-c-format
msgid ""
"You now need to configure a logging system. Hibernate uses commons logging "
"and provides two choices: Log4j and JDK 1.4 logging. Most developers prefer "
"Log4j: copy <literal>log4j.properties from the Hibernate "
"distribution in the <literal>etc/ directory to your srchibernate.cfg.xml. If you "
"prefer to have more verbose output than that provided in the example "
"configuration, you can change the settings. By default, only the Hibernate "
"startup message is shown on stdout."
msgstr ""
"å†æ¬¡ç¼–译这个应用程åºåº”该ä¸ä¼šæœ‰é—®é¢˜ã€‚最åŽæˆ‘们需è¦é…置一个日志(logging)系统 — "
"Hibernate 使用通用日志接å£ï¼Œå…è®¸ä½ åœ¨ Log4j å’Œ JDK 1.4 日志之间进行选择。多数"
"å¼€å‘者更喜欢 Log4j:从 Hibernate çš„å‘布包ä¸ï¼ˆå®ƒåœ¨ <literal>etc/ ç›®"
"å½•ä¸‹ï¼‰æ‹·è´ <literal>log4j.properties åˆ°ä½ çš„ src "
"目录,与 <literal>hibernate.cfg.xml 放在一起。看一下é…置示例,如果"
"ä½ å¸Œæœ›çœ‹åˆ°æ›´åŠ è¯¦ç»†çš„è¾“å‡ºä¿¡æ¯ï¼Œä½ å¯ä»¥ä¿®æ”¹é…置。默认情况下,åªæœ‰ Hibernate çš„å¯"
"动信æ¯æ‰ä¼šæ˜¾ç¤ºåœ¨æ ‡å‡†è¾“出上。 "
#. Tag: para
#: tutorial.xml:480
#, no-c-format
msgid ""
"The tutorial infrastructure is complete and you are now ready to do some "
"real work with Hibernate."
msgstr "示例的基本框架完æˆäº† — 现在我们å¯ä»¥ç”¨ Hibernate æ¥åšäº›çœŸæ£çš„工作。 "
#. Tag: title
#: tutorial.xml:488
#, no-c-format
msgid "Loading and storing objects"
msgstr "åŠ è½½å¹¶å˜å‚¨å¯¹è±¡"
#. Tag: para
#: tutorial.xml:490
#, fuzzy, no-c-format
msgid ""
"We are now ready to start doing some real work with Hibernate. Let's start "
"by writing an <literal>EventManager class with a main()EventManager 类: "
#. Tag: programlisting
#: tutorial.xml:496
#, fuzzy, no-c-format
msgid ""
"<![CDATA[package org.hibernate.tutorial;\n"
"\n"
"import org.hibernate.Session;\n"
"\n"
"import java.util.*;\n"
"\n"
"import org.hibernate.tutorial.domain.Event;\n"
"import org.hibernate.tutorial.util.HibernateUtil;\n"
"\n"
"public class EventManager {\n"
"\n"
" public static void main(String[] args) {\n"
" EventManager mgr = new EventManager();\n"
"\n"
" if (args[0].equals(\"store\")) {\n"
" mgr.createAndStoreEvent(\"My Event\", new Date());\n"
" }\n"
"\n"
" HibernateUtil.getSessionFactory().close();\n"
" }\n"
"\n"
" private void createAndStoreEvent(String title, Date theDate) {\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
"\n"
" Event theEvent = new Event();\n"
" theEvent.setTitle(title);\n"
" theEvent.setDate(theDate);\n"
" session.save(theEvent);\n"
"\n"
" session.getTransaction().commit();\n"
" }\n"
"\n"
"}]]>"
msgstr ""
"package events;\n"
"import org.hibernate.Session;\n"
"\n"
"import java.util.Date;\n"
"\n"
"import util.HibernateUtil;\n"
"\n"
"public class EventManager {\n"
"\n"
" public static void main(String[] args) {\n"
" EventManager mgr = new EventManager();\n"
"\n"
" if (args[0].equals(\"store\")) {\n"
" mgr.createAndStoreEvent(\"My Event\", new Date());\n"
" }\n"
"\n"
" HibernateUtil.getSessionFactory().close();\n"
" }\n"
"\n"
" private void createAndStoreEvent(String title, Date theDate) {\n"
"\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
"\n"
" session.beginTransaction();\n"
"\n"
" Event theEvent = new Event();\n"
" theEvent.setTitle(title);\n"
" theEvent.setDate(theDate);\n"
"\n"
" session.save(theEvent);\n"
"\n"
" session.getTransaction().commit();\n"
" }\n"
"\n"
"}"
#. Tag: para
#: tutorial.xml:498
#, no-c-format
msgid ""
"In <literal>createAndStoreEvent() we created a new Event on the "
"database."
msgstr ""
"在 <literal>createAndStoreEvent() æ¥é‡Œæˆ‘们创建了一个新的 "
"<literal>Event å¯¹è±¡å¹¶æŠŠå®ƒä¼ é€’ç»™ Hibernate。现在 Hibernate 负责与 "
"SQL 打交é“,并把 <literal>INSERT å‘½ä»¤ä¼ ç»™æ•°æ®åº“。"
#. Tag: para
#: tutorial.xml:505
#, fuzzy, no-c-format
msgid ""
"A <interface>org.hibernate.Session is designed to represent a "
"single unit of work (a single atomic piece of work to be performed). For now "
"we will keep things simple and assume a one-to-one granularity between a "
"Hibernate <interface>org.hibernate.Session and a database "
"transaction. To shield our code from the actual underlying transaction "
"system we use the Hibernate <interfacename>org.hibernate.Transaction 就是个å•ä¸€çš„工作å•å…ƒã€‚我们"
"暂时让事情简å•ä¸€äº›ï¼Œå¹¶å‡è®¾ Hibernate <interface>org.hibernate.Session do? First, "
"you can call it as many times and anywhere you like once you get hold of "
"your <interfacename>org.hibernate.SessionFactory. The "
"<literal>getCurrentSession() method always returns the \"current\" "
"unit of work. Remember that we switched the configuration option for this "
"mechanism to \"thread\" in our <filename>src/main/resources/hibernate.cfg."
"xml</filename>? Due to that setting, the context of a current unit of work "
"is bound to the current Java thread that executes the application."
msgstr ""
"<literal>sessionFactory.getCurrentSession() 是干什么的呢?首先,åª"
"è¦ä½ æŒæœ‰ <interfacename>org.hibernate.SessionFactory,大å¯åœ¨"
"任何时候ã€ä»»ä½•åœ°ç‚¹è°ƒç”¨è¿™ä¸ªæ–¹æ³•ã€‚<literal>getCurrentSession() 方法总"
"会返回“当å‰çš„â€å·¥ä½œå•å…ƒã€‚记得我们在 <filename>src/main/resources/hibernate."
"cfg.xml</filename> ä¸æŠŠè¿™ä¸€é…置选项调整为 \"thread\" 了å—ï¼Ÿå› æ¤ï¼Œå› æ¤ï¼Œå½“å‰å·¥"
"作å•å…ƒè¢«ç»‘定到当å‰æ‰§è¡Œæˆ‘们应用程åºçš„ Java 线程。但是,这并éžæ˜¯å®Œå…¨å‡†ç¡®çš„,ä½ è¿˜"
"得考虑工作å•å…ƒçš„生命周期范围(scope),它何时开始,åˆä½•æ—¶ç»“æŸã€‚"
#. Tag: para
#: tutorial.xml:532
#, no-c-format
msgid ""
"Hibernate offers three methods of current session tracking. The \"thread\" "
"based method is not intended for production use; it is merely useful for "
"prototyping and tutorials such as this one. Current session tracking is "
"discussed in more detail later on."
msgstr ""
"Hibernate æ供三ç§è·Ÿè¸ªå½“å‰ä¼šè¯çš„方法。基于“线程â€çš„方法ä¸é€‚åˆäºŽäº§å“环境,它仅"
"用于 prototyping 和教å¦ç”¨é€”。åŽé¢å°†æ›´è¯¦ç»†åœ°è®¨è®ºä¼šè¯è·Ÿè¸ªã€‚"
#. Tag: para
#: tutorial.xml:541
#, no-c-format
msgid ""
"A <interface>org.hibernate.Session begins when the first call to "
"<literal>getCurrentSession() is made for the current thread. It is "
"then bound by Hibernate to the current thread. When the transaction ends, "
"either through commit or rollback, Hibernate automatically unbinds the "
"<interface>org.hibernate.Session from the thread and closes it "
"for you. If you call <literal>getCurrentSession() again, you get a "
"new <interface>org.hibernate.Session and can start a new unit of "
"work."
msgstr ""
"<interface>org.hibernate.Session 在第一次被使用的时候,å³ç¬¬ä¸€æ¬¡è°ƒ"
"用 <literal>getCurrentSession() 的时候,其生命周期就开始。然åŽå®ƒè¢« "
"Hibernate 绑定到当å‰çº¿ç¨‹ã€‚当事务结æŸçš„时候,ä¸ç®¡æ˜¯æ交还是回滚,Hibernate 会"
"自动把 <interface>org.hibernate.Session 从当å‰çº¿ç¨‹å‰¥ç¦»ï¼Œå¹¶ä¸”å…³é—"
"它。å‡è‹¥ä½ å†æ¬¡è°ƒç”¨ <literal>getCurrentSession()ï¼Œä½ ä¼šå¾—åˆ°ä¸€ä¸ªæ–°çš„ "
"<interface>org.hibernate.Session,并且开始一个新的工作å•å…ƒã€‚"
#. Tag: para
#: tutorial.xml:554
#, no-c-format
msgid ""
"Related to the unit of work scope, should the Hibernate <interface>org."
"hibernate.Session</interface> be used to execute one or several database "
"operations? The above example uses one <interface>org.hibernate.Session is flexible but you "
"should never design your application to use a new Hibernate <interface>org."
"hibernate.Session</interface> for every database "
"operation. Even though it is used in the following examples, consider "
"<emphasis>session-per-operation an anti-pattern. A real web "
"application is shown later in the tutorial which will help illustrate this."
msgstr ""
"和工作å•å…ƒçš„生命周期这个è¯é¢˜ç›¸å…³ï¼ŒHibernate <interface>org.hibernate."
"Session</interface> 是å¦è¢«åº”该用æ¥æ‰§è¡Œå¤šæ¬¡æ•°æ®åº“æ“作?上é¢çš„例å对æ¯ä¸€æ¬¡æ“作"
"使用了一个 <interface>org.hibernate.Session,这完全是巧åˆï¼Œè¿™ä¸ªä¾‹"
"åä¸æ˜¯å¾ˆå¤æ‚ï¼Œæ— æ³•å±•ç¤ºå…¶ä»–æ–¹å¼ã€‚Hibernate <interface>org.hibernate.Session"
"æ¯ä¸€æ¬¡</emphasis>æ•°æ®åº“æ“作都用一个新的 Hibernate org.hibernate."
"Session</interface>ã€‚å› æ¤å°±ç®—下é¢çš„例å(它们都很简å•ï¼‰ä¸ä½ å¯ä»¥çœ‹åˆ°è¿™ç§ç”¨æ³•ï¼Œ"
"è®°ä½<emphasis>æ¯æ¬¡æ“作一个 session 是一个å模å¼ã€‚在本教程的åŽé¢ä¼š"
"展示一个真æ£çš„(web)程åºã€‚"
#. Tag: para
#: tutorial.xml:571
#, fuzzy, no-c-format
msgid ""
"See <xref linkend=\"transactions\"/> for more information about transaction "
"handling and demarcation. The previous example also skipped any error "
"handling and rollback."
msgstr ""
"关于事务处ç†åŠäº‹åŠ¡è¾¹ç•Œç•Œå®šçš„详细信æ¯ï¼Œè¯·å‚看 <xref linkend=\"transactions\" /"
"> 。在上é¢çš„例åä¸ï¼Œæˆ‘们也忽略了所有的错误与回滚的处ç†ã€‚ "
#. Tag: para
#: tutorial.xml:577
#, no-c-format
msgid ""
"To run this, we will make use of the Maven exec plugin to call our class "
"with the necessary classpath setup: <command>mvn exec:java -Dexec.mainClass="
"\"org.hibernate.tutorial.EventManager\" -Dexec.args=\"store\"</command>"
msgstr ""
"è¦è¿è¡Œå®ƒï¼Œæˆ‘们将使用 Maven exec æ’件以åŠå¿…è¦çš„ classpath 设置æ¥è¿›è¡Œè°ƒç”¨ï¼š"
"<command>mvn exec:java -Dexec.mainClass=\"org.hibernate.tutorial.EventManager"
"\" -Dexec.args=\"store\"</command>。"
#. Tag: para
#: tutorial.xml:584
#, no-c-format
msgid "You may need to perform <command>mvn compile first."
msgstr "ä½ å¯èƒ½éœ€è¦å…ˆæ‰§è¡Œ <command>mvn compile。"
#. Tag: para
#: tutorial.xml:589
#, no-c-format
msgid ""
"You should see Hibernate starting up and, depending on your configuration, "
"lots of log output. Towards the end, the following line will be displayed:"
msgstr ""
"ä½ åº”è¯¥ä¼šçœ‹åˆ°ï¼Œç¼–è¯‘ä»¥åŽï¼ŒHibernate æ ¹æ®ä½ çš„é…ç½®å¯åŠ¨ï¼Œå¹¶äº§ç”Ÿä¸€å¤§å †çš„输出日志。"
"在日志最åŽä½ 会看到下é¢è¿™è¡Œï¼š "
#. Tag: programlisting
#: tutorial.xml:594
#, fuzzy, no-c-format
msgid ""
"<![CDATA[[java] Hibernate: insert into EVENTS (EVENT_DATE, title, EVENT_ID) "
"values (?, ?, ?)]]>"
msgstr ""
"[java] Hibernate: insert into EVENTS (EVENT_DATE, title, EVENT_ID) values "
"(?, ?, ?)"
#. Tag: para
#: tutorial.xml:596
#, no-c-format
msgid "This is the <literal>INSERT executed by Hibernate."
msgstr "执行 HQL <literal>INSERT è¯å¥çš„例å如下: "
#. Tag: para
#: tutorial.xml:600
#, no-c-format
msgid "To list stored events an option is added to the main method:"
msgstr ""
"我们想è¦åˆ—出所有已ç»è¢«å˜å‚¨çš„ events,就è¦å¢žåŠ 一个æ¡ä»¶åˆ†æ”¯é€‰é¡¹åˆ° main 方法ä¸ï¼š"
#. Tag: programlisting
#: tutorial.xml:604
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ if (args[0].equals(\"store\")) {\n"
" mgr.createAndStoreEvent(\"My Event\", new Date());\n"
" }\n"
" else if (args[0].equals(\"list\")) {\n"
" List events = mgr.listEvents();\n"
" for (int i = 0; i < events.size(); i++) {\n"
" Event theEvent = (Event) events.get(i);\n"
" System.out.println(\n"
" \"Event: \" + theEvent.getTitle() + \" Time: \" + "
"theEvent.getDate()\n"
" );\n"
" }\n"
" }]]>"
msgstr ""
"if (args[0].equals(\"store\")) {\n"
" mgr.createAndStoreEvent(\"My Event\", new Date());\n"
"}\n"
"else if (args[0].equals(\"list\")) {\n"
" List events = mgr.listEvents();\n"
" for (int i = 0; i < events.size(); i++) {\n"
" Event theEvent = (Event) events.get(i);\n"
" System.out.println(\"Event: \" + theEvent.getTitle() +\n"
" \" Time: \" + theEvent.getDate());\n"
" }\n"
"}"
#. Tag: para
#: tutorial.xml:606
#, no-c-format
msgid "A new <literal>listEvents() method is also added:"
msgstr "æˆ‘ä»¬ä¹Ÿå¢žåŠ ä¸€ä¸ªæ–°çš„ <literal>listEvents() 方法: "
#. Tag: programlisting
#: tutorial.xml:610
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private List listEvents() {\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
" List result = session.createQuery(\"from Event\").list();\n"
" session.getTransaction().commit();\n"
" return result;\n"
" }]]>"
msgstr ""
"private List listEvents() {\n"
"\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
"\n"
" session.beginTransaction();\n"
"\n"
" List result = session.createQuery(\"from Event\").list();\n"
"\n"
" session.getTransaction().commit();\n"
"\n"
" return result;\n"
"}"
#. Tag: para
#: tutorial.xml:612
#, fuzzy, no-c-format
msgid ""
"Here, we are using a Hibernate Query Language (HQL) query to load all "
"existing <literal>Event objects from the database. Hibernate will "
"generate the appropriate SQL, send it to the database and populate "
"<literal>Event objects with the data. You can create more complex "
"queries with HQL. See <xref linkend=\"queryhql\"/> for more information."
msgstr ""
"我们在这里是用一个 HQL(Hibernate Query Languageï¼Hibernate查询è¯è¨€ï¼‰æŸ¥è¯¢è¯å¥"
"æ¥ä»Žæ•°æ®åº“ä¸åŠ 载所有å˜åœ¨çš„ <literal>Event 对象。Hibernate 会生æˆé€‚"
"当的 SQL,把它å‘é€åˆ°æ•°æ®åº“,并æ“作从查询得到数æ®çš„ <literal>Event "
"å¯¹è±¡ã€‚å½“ç„¶ï¼Œä½ å¯ä»¥ä½¿ç”¨ HQL æ¥åˆ›å»ºæ›´åŠ å¤æ‚的查询。更多信æ¯è¯·å‚考 <xref "
"linkend=\"queryhql\"/>。 "
#. Tag: para
#: tutorial.xml:620
#, no-c-format
msgid ""
"Now we can call our new functionality, again using the Maven exec plugin: "
"<command>mvn exec:java -Dexec.mainClass=\"org.hibernate.tutorial.EventManager"
"\" -Dexec.args=\"list\"</command>"
msgstr ""
"现在我们å¯ä»¥å†æ¬¡ç”¨ Maven exec plugin - <command>mvn exec:java -Dexec."
"mainClass=\"org.hibernate.tutorial.EventManager\" -Dexec.args=\"list\"</"
"command> 调用新的功能了。"
#. Tag: title
#: tutorial.xml:630
#, no-c-format
msgid "Part 2 - Mapping associations"
msgstr "第二部分 ï¼ å…³è”æ˜ å°„"
#. Tag: para
#: tutorial.xml:632
#, no-c-format
msgid ""
"So far we have mapped a single persistent entity class to a table in "
"isolation. Let's expand on that a bit and add some class associations. We "
"will add people to the application and store a list of events in which they "
"participate."
msgstr ""
"我们已ç»æ˜ 射了一个æŒä¹…åŒ–å®žä½“ç±»åˆ°è¡¨ä¸Šã€‚è®©æˆ‘ä»¬åœ¨è¿™ä¸ªåŸºç¡€ä¸Šå¢žåŠ ä¸€äº›ç±»ä¹‹é—´çš„å…³"
"è”。首先我们往应用程åºé‡Œå¢žåŠ 人(people)的概念,并å˜å‚¨ä»–们所å‚与的一个 Event "
"列表。(译者注:与 Event ä¸€æ ·ï¼Œæˆ‘ä»¬åœ¨åŽé¢å°†ç›´æŽ¥ä½¿ç”¨ person æ¥è¡¨ç¤ºâ€œäººâ€è€Œä¸æ˜¯å®ƒ"
"çš„ä¸æ–‡ç¿»è¯‘) "
#. Tag: title
#: tutorial.xml:640
#, no-c-format
msgid "Mapping the Person class"
msgstr "æ˜ å°„ Person ç±»"
#. Tag: para
#: tutorial.xml:642
#, no-c-format
msgid "The first cut of the <literal>Person class looks like this:"
msgstr "最åˆç®€å•çš„ <literal>Person 类: "
#. Tag: programlisting
#: tutorial.xml:646
#, fuzzy, no-c-format
msgid ""
"<![CDATA[package org.hibernate.tutorial.domain;\n"
"\n"
"public class Person {\n"
"\n"
" private Long id;\n"
" private int age;\n"
" private String firstname;\n"
" private String lastname;\n"
"\n"
" public Person() {}\n"
"\n"
" // Accessor methods for all properties, private setter for 'id'\n"
"\n"
"}]]>"
msgstr ""
"package events;\n"
"\n"
"public class Person {\n"
"\n"
" private Long id;\n"
" private int age;\n"
" private String firstname;\n"
" private String lastname;\n"
"\n"
" public Person() {}\n"
"\n"
" // Accessor methods for all properties, private setter for 'id'\n"
"\n"
"}"
#. Tag: para
#: tutorial.xml:648
#, no-c-format
msgid ""
"Save this to a file named <filename>src/main/java/org/hibernate/tutorial/"
"domain/Person.java</filename>"
msgstr ""
"把它ä¿å˜ä¸ºæ–‡ä»¶ <filename>src/main/java/org/hibernate/tutorial/domain/Person."
"java</filename>。"
#. Tag: para
#: tutorial.xml:653
#, no-c-format
msgid ""
"Next, create the new mapping file as <filename>src/main/resources/org/"
"hibernate/tutorial/domain/Person.hbm.xml</filename>"
msgstr ""
"然åŽï¼Œåˆ›å»ºæ–°çš„æ˜ å°„æ–‡ä»¶ <filename>src/main/resources/org/hibernate/tutorial/"
"domain/Person.hbm.xml</filename>。"
#. Tag: programlisting
#: tutorial.xml:658
#, fuzzy, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<hibernate-mapping>\n"
"\n"
" <class name=\"events.Person\" table=\"PERSON\">\n"
" <id name=\"id\" column=\"PERSON_ID\">\n"
" <generator class=\"native\"/>\n"
" </id>\n"
" <property name=\"age\"/>\n"
" <property name=\"firstname\"/>\n"
" <property name=\"lastname\"/>\n"
" </class>\n"
"\n"
"</hibernate-mapping>"
#. Tag: para
#: tutorial.xml:660
#, no-c-format
msgid "Finally, add the new mapping to Hibernate's configuration:"
msgstr "最åŽï¼ŒæŠŠæ–°çš„æ˜ å°„åŠ å…¥åˆ° Hibernate çš„é…ç½®ä¸ï¼š"
#. Tag: programlisting
#: tutorial.xml:664
#, fuzzy, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<mapping resource=\"events/Event.hbm.xml\"/>\n"
"<mapping resource=\"events/Person.hbm.xml\"/>"
#. Tag: para
#: tutorial.xml:666
#, no-c-format
msgid ""
"Create an association between these two entities. Persons can participate in "
"events, and events have participants. The design questions you have to deal "
"with are: directionality, multiplicity, and collection behavior."
msgstr ""
"现在我们在这两个实体之间创建一个关è”。显然,persons å¯ä»¥å‚与一系列 events,"
"而 events 也有ä¸åŒçš„å‚åŠ è€…ï¼ˆpersons)。我们需è¦å¤„ç†çš„设计问题是关è”æ–¹å‘"
"(directionality),阶数(multiplicity)和集åˆï¼ˆcollection)的行为。 "
#. Tag: title
#: tutorial.xml:676
#, no-c-format
msgid "A unidirectional Set-based association"
msgstr "å•å‘ Set-based çš„å…³è”"
#. Tag: para
#: tutorial.xml:678
#, no-c-format
msgid ""
"By adding a collection of events to the <literal>Person class, you "
"can easily navigate to the events for a particular person, without executing "
"an explicit query - by calling <literal>Person#getEvents. Multi-"
"valued associations are represented in Hibernate by one of the Java "
"Collection Framework contracts; here we choose a <interfacename>java.util."
"Set</interfacename> because the collection will not contain duplicate "
"elements and the ordering is not relevant to our examples:"
msgstr ""
"æˆ‘ä»¬å°†å‘ <literal>Person ç±»å¢žåŠ ä¸€è¿žä¸²çš„ eventsã€‚é‚£æ ·ï¼Œé€šè¿‡è°ƒç”¨ "
"<literal>aPerson.getEvents(),就å¯ä»¥è½»æ¾åœ°å¯¼èˆªåˆ°ç‰¹å®š person 所å‚与"
"çš„ events,而ä¸ç”¨åŽ»æ‰§è¡Œä¸€ä¸ªæ˜¾å¼çš„查询。我们使用 Java 的集åˆç±»ï¼ˆcollection):"
"<literal>Setï¼Œå› ä¸º set ä¸åŒ…å«é‡å¤çš„å…ƒç´ åŠä¸Žæˆ‘ä»¬æ— å…³çš„æŽ’åºã€‚ "
#. Tag: programlisting
#: tutorial.xml:689
#, fuzzy, no-c-format
msgid ""
"<![CDATA[public class Person {\n"
"\n"
" private Set events = new HashSet();\n"
"\n"
" public Set getEvents() {\n"
" return events;\n"
" }\n"
"\n"
" public void setEvents(Set events) {\n"
" this.events = events;\n"
" }\n"
"}]]>"
msgstr ""
"public class Person {\n"
"\n"
" private Set events = new HashSet();\n"
"\n"
" public Set getEvents() {\n"
" return events;\n"
" }\n"
"\n"
" public void setEvents(Set events) {\n"
" this.events = events;\n"
" }\n"
"}"
#. Tag: para
#: tutorial.xml:691
#, no-c-format
msgid ""
"Before mapping this association, let's consider the other side. We could "
"just keep this unidirectional or create another collection on the "
"<literal>Event, if we wanted to be able to navigate it from both "
"directions. This is not necessary, from a functional perspective. You can "
"always execute an explicit query to retrieve the participants for a "
"particular event. This is a design choice left to you, but what is clear "
"from this discussion is the multiplicity of the association: \"many\" valued "
"on both sides is called a <emphasis>many-to-many association. "
"Hence, we use Hibernate's many-to-many mapping:"
msgstr ""
"åœ¨æ˜ å°„è¿™ä¸ªå…³è”之å‰ï¼Œå…ˆè€ƒè™‘一下æ¤å…³è”çš„å¦å¤–一端。很显然,我们å¯ä»¥ä¿æŒè¿™ä¸ªå…³è”"
"是å•å‘的。或者,我们å¯ä»¥åœ¨ <literal>Event 里创建å¦å¤–一个集åˆï¼Œå¦‚æžœ"
"希望能够åŒå‘地导航,如:<literal>anEvent.getParticipants()。从功能"
"的角度æ¥è¯´ï¼Œè¿™å¹¶ä¸æ˜¯å¿…é¡»çš„ã€‚å› ä¸ºä½ æ€»å¯ä»¥æ˜¾å¼åœ°æ‰§è¡Œä¸€ä¸ªæŸ¥è¯¢ï¼Œä»¥èŽ·å¾—æŸä¸ªç‰¹å®š "
"event 的所有å‚与者。这是个在设计时需è¦åšå‡ºçš„é€‰æ‹©ï¼Œå®Œå…¨ç”±ä½ æ¥å†³å®šï¼Œä½†æ¤è®¨è®ºä¸"
"关于关è”的阶数是清楚的:å³ä¸¤ç«¯éƒ½æ˜¯â€œå¤šâ€å€¼çš„,我们把它å«åš<emphasis>多对多"
"(many-to-many)</emphasis>å…³è”ã€‚å› è€Œï¼Œæˆ‘ä»¬ä½¿ç”¨ Hibernate çš„å¤šå¯¹å¤šæ˜ å°„ï¼š "
#. Tag: programlisting
#: tutorial.xml:704
#, fuzzy, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<class name=\"events.Person\" table=\"PERSON\">\n"
" <id name=\"id\" column=\"PERSON_ID\">\n"
" <generator class=\"native\"/>\n"
" </id>\n"
" <property name=\"age\"/>\n"
" <property name=\"firstname\"/>\n"
" <property name=\"lastname\"/>\n"
"\n"
" <set name=\"events\" table=\"PERSON_EVENT\">\n"
" <key column=\"PERSON_ID\"/>\n"
" <many-to-many column=\"EVENT_ID\" class=\"events.Event\"/>\n"
" </set>\n"
"\n"
"</class>"
#. Tag: para
#: tutorial.xml:706
#, no-c-format
msgid ""
"Hibernate supports a broad range of collection mappings, a <literal>setn:"
"m</emphasis> entity relationship, an association table is required. Each row "
"in this table represents a link between a person and an event. The table "
"name is decalred using the <literal>table attribute of the "
"<literal>set element. The identifier column name in the "
"association, for the person side, is defined with the <literal>key "
"element, the column name for the event's side with the <literal>columnmany-to-many. You also have to "
"tell Hibernate the class of the objects in your collection (the class on the "
"other side of the collection of references)."
msgstr ""
"Hibernate 支æŒå„ç§å„æ ·çš„é›†åˆæ˜ 射,<literal><set> 使用的最为普"
"é。对于多对多关è”ï¼ˆæˆ–å« <emphasis>n:m 实体关系), 需è¦ä¸€ä¸ªå…³è”表"
"(association table)。<literal>表里é¢çš„æ¯ä¸€è¡Œä»£è¡¨ä»Ž person 到 "
"event 的一个关è”。表å是由 <literal>set å…ƒç´ çš„ table å…ƒç´ å®šä¹‰ï¼Œè€Œ event 一端的å—段å是由 "
"<literal><many-to-many> å…ƒç´ çš„ column 属性"
"å®šä¹‰ã€‚ä½ ä¹Ÿå¿…é¡»å‘Šè¯‰ Hibernate 集åˆä¸å¯¹è±¡çš„类(也就是ä½äºŽè¿™ä¸ªé›†åˆæ‰€ä»£è¡¨çš„å…³è”å¦"
"外一端的类)。 "
#. Tag: para
#: tutorial.xml:722
#, no-c-format
msgid "The database schema for this mapping is therefore:"
msgstr "å› è€Œè¿™ä¸ªæ˜ å°„çš„æ•°æ®åº“ schema 是:"
#. Tag: programlisting
#: tutorial.xml:726
#, fuzzy, no-c-format
msgid ""
"<![CDATA[\n"
" _____________ __________________\n"
" | | | | _____________\n"
" | EVENTS | | PERSON_EVENT | | |\n"
" |_____________| |__________________| | PERSON |\n"
" | | | | |_____________|\n"
" | *EVENT_ID | <--> | *EVENT_ID | | |\n"
" | EVENT_DATE | | *PERSON_ID | <--> | *PERSON_ID |\n"
" | TITLE | |__________________| | AGE |\n"
" |_____________| | FIRSTNAME |\n"
" | LASTNAME |\n"
" |_____________|\n"
" ]]>"
msgstr ""
"_____________ __________________\n"
" | | | | _____________\n"
" | EVENTS | | PERSON_EVENT | | |\n"
" |_____________| |__________________| | PERSON |\n"
" | | | | |_____________|\n"
" | *EVENT_ID | <--> | *EVENT_ID | | |\n"
" | EVENT_DATE | | *PERSON_ID | <--> | *PERSON_ID |\n"
" | TITLE | |__________________| | AGE |\n"
" |_____________| | FIRSTNAME |\n"
" | LASTNAME |\n"
" |_____________|"
#. Tag: title
#: tutorial.xml:731
#, no-c-format
msgid "Working the association"
msgstr "使关è”工作"
#. Tag: para
#: tutorial.xml:733
#, no-c-format
msgid ""
"Now we will bring some people and events together in a new method in "
"<literal>EventManager:"
msgstr ""
"我们把一些 people 和 events 一起放到 <literal>EventManager 的新方法"
"ä¸ï¼š "
#. Tag: programlisting
#: tutorial.xml:737
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private void addPersonToEvent(Long personId, Long eventId) {\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
"\n"
" Person aPerson = (Person) session.load(Person.class, personId);\n"
" Event anEvent = (Event) session.load(Event.class, eventId);\n"
" aPerson.getEvents().add(anEvent);\n"
"\n"
" session.getTransaction().commit();\n"
" }]]>"
msgstr ""
"private void addPersonToEvent(Long personId, Long eventId) {\n"
"\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
"\n"
" Person aPerson = (Person) session.load(Person.class, personId);\n"
" Event anEvent = (Event) session.load(Event.class, eventId);\n"
"\n"
" aPerson.getEvents().add(anEvent);\n"
"\n"
" session.getTransaction().commit();\n"
"}"
#. Tag: para
#: tutorial.xml:739
#, no-c-format
msgid ""
"After loading a <literal>Person and an Event, "
"simply modify the collection using the normal collection methods. There is "
"no explicit call to <literal>update() or save() state, that is, bound to a particular "
"Hibernate <interfacename>org.hibernate.Session, Hibernate "
"monitors any changes and executes SQL in a write-behind fashion. The process "
"of synchronizing the memory state with the database, usually only at the end "
"of a unit of work, is called <emphasis>flushing. In our code, the "
"unit of work ends with a commit, or rollback, of the database transaction."
msgstr ""
"åœ¨åŠ è½½ä¸€ <literal>Person å’Œ Event åŽï¼Œä½¿ç”¨æ™®é€šçš„"
"集åˆæ–¹æ³•å°±å¯å®¹æ˜“地修改我们定义的集åˆã€‚å¦‚ä½ æ‰€è§ï¼Œæ²¡æœ‰æ˜¾å¼çš„ <literal>update()"
"</literal> 或 save(),Hibernate 会自动检测到集åˆå·²ç»è¢«ä¿®æ”¹"
"并需è¦æ›´æ–°å›žæ•°æ®åº“。这å«åšè‡ªåŠ¨è„检查(<emphasis>automatic dirty checking状æ€ï¼Œä¹Ÿå°±æ˜¯è¢«ç»‘定到æŸä¸ª Hibernate çš„ "
"<literal>Session 上(如:他们刚刚在一个å•å…ƒæ“ä½œè¢«åŠ è½½æˆ–è€…ä¿å˜ï¼‰ï¼Œ"
"Hibernate 监视任何改å˜å¹¶åœ¨åŽå°éšå¼å†™çš„æ–¹å¼æ‰§è¡Œ SQL。åŒæ¥å†…å˜çŠ¶æ€å’Œæ•°æ®åº“的过"
"程,通常åªåœ¨å•å…ƒæ“作结æŸçš„时候å‘生,称æ¤è¿‡ç¨‹ä¸ºæ¸…ç†ç¼“å˜<emphasis>(flushing)"
"</emphasis>。在我们的代ç ä¸ï¼Œå·¥ä½œå•å…ƒç”±æ•°æ®åº“事务的æ交(或者回滚)æ¥ç»“æŸâ€”—这"
"是由 <literal>CurrentSessionContext 类的 thread "
"é…置选项定义的。 "
#. Tag: para
#: tutorial.xml:758
#, no-c-format
msgid ""
"You can load person and event in different units of work. Or you can modify "
"an object outside of a <interfacename>org.hibernate.Session, "
"when it is not in persistent state (if it was persistent before, this state "
"is called <emphasis>detached). You can even modify a collection "
"when it is detached:"
msgstr ""
"å½“ç„¶ï¼Œä½ ä¹Ÿå¯ä»¥åœ¨ä¸åŒçš„å•å…ƒæ“作里é¢åŠ è½½ person å’Œ event。或在 "
"<literal>Session 以外修改ä¸æ˜¯å¤„在æŒä¹…化(persistent)状æ€ä¸‹çš„对象"
"(如果该对象以å‰æ›¾ç»è¢«æŒä¹…化,那么我们称这个状æ€ä¸º<emphasis>脱管(detached)"
"</emphasis>ï¼‰ã€‚ä½ ç”šè‡³å¯ä»¥åœ¨ä¸€ä¸ªé›†åˆè¢«è„±ç®¡æ—¶ä¿®æ”¹å®ƒï¼š "
#. Tag: programlisting
#: tutorial.xml:767
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private void addPersonToEvent(Long personId, Long eventId) {\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
"\n"
" Person aPerson = (Person) session\n"
" .createQuery(\"select p from Person p left join fetch p."
"events where p.id = :pid\")\n"
" .setParameter(\"pid\", personId)\n"
" .uniqueResult(); // Eager fetch the collection so we can use "
"it detached\n"
" Event anEvent = (Event) session.load(Event.class, eventId);\n"
"\n"
" session.getTransaction().commit();\n"
"\n"
" // End of first unit of work\n"
"\n"
" aPerson.getEvents().add(anEvent); // aPerson (and its collection) is "
"detached\n"
"\n"
" // Begin second unit of work\n"
"\n"
" Session session2 = HibernateUtil.getSessionFactory()."
"getCurrentSession();\n"
" session2.beginTransaction();\n"
" session2.update(aPerson); // Reattachment of aPerson\n"
"\n"
" session2.getTransaction().commit();\n"
" }]]>"
msgstr ""
"private void addPersonToEvent(Long personId, Long eventId) {\n"
"\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
"\n"
" Person aPerson = (Person) session\n"
" .createQuery(\"select p from Person p left join fetch p.events "
"where p.id = :pid\")\n"
" .setParameter(\"pid\", personId)\n"
" .uniqueResult(); // Eager fetch the collection so we can use it "
"detached\n"
"\n"
" Event anEvent = (Event) session.load(Event.class, eventId);\n"
"\n"
" session.getTransaction().commit();\n"
"\n"
" // End of first unit of work\n"
"\n"
" aPerson.getEvents().add(anEvent); // aPerson (and its collection) is "
"detached\n"
"\n"
" // Begin second unit of work\n"
"\n"
" Session session2 = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session2.beginTransaction();\n"
"\n"
" session2.update(aPerson); // Reattachment of aPerson\n"
"\n"
" session2.getTransaction().commit();\n"
"}"
#. Tag: para
#: tutorial.xml:769
#, no-c-format
msgid ""
"The call to <literal>update makes a detached object persistent "
"again by binding it to a new unit of work, so any modifications you made to "
"it while detached can be saved to the database. This includes any "
"modifications (additions/deletions) you made to a collection of that entity "
"object."
msgstr ""
"对 <literal>update 的调用使一个脱管对象é‡æ–°æŒä¹…åŒ–ï¼Œä½ å¯ä»¥è¯´å®ƒè¢«ç»‘定"
"到一个新的å•å…ƒæ“作上,所以在脱管状æ€ä¸‹å¯¹å®ƒæ‰€åšçš„任何修改都会被ä¿å˜åˆ°æ•°æ®åº“"
"é‡Œã€‚è¿™ä¹ŸåŒ…æ‹¬ä½ å¯¹è¿™ä¸ªå®žä½“å¯¹è±¡çš„é›†åˆæ‰€ä½œçš„ä»»ä½•æ”¹åŠ¨ï¼ˆå¢žåŠ /åˆ é™¤ï¼‰ã€‚ "
#. Tag: para
#: tutorial.xml:778
#, no-c-format
msgid ""
"This is not much use in our example, but it is an important concept you can "
"incorporate into your own application. Complete this exercise by adding a "
"new action to the main method of the <literal>EventManager and "
"call it from the command line. If you need the identifiers of a person and "
"an event - the <literal>save() method returns it (you might have "
"to modify some of the previous methods to return that identifier):"
msgstr ""
"这对我们当å‰çš„情形ä¸æ˜¯å¾ˆæœ‰ç”¨ï¼Œä½†å®ƒæ˜¯éžå¸¸é‡è¦çš„æ¦‚å¿µï¼Œä½ å¯ä»¥æŠŠå®ƒèžå…¥åˆ°ä½ 自己的"
"应用程åºè®¾è®¡ä¸ã€‚在<literal>EventManagerçš„ main 方法ä¸æ·»åŠ 一个新的动"
"作,并从命令行è¿è¡Œå®ƒæ¥å®Œæˆæˆ‘们所åšçš„ç»ƒä¹ ã€‚å¦‚æžœä½ éœ€è¦ person åŠ event çš„æ ‡è¯†"
"符 — 那就用 <literal>save() æ–¹æ³•è¿”å›žå®ƒï¼ˆä½ å¯èƒ½éœ€è¦ä¿®æ”¹å‰é¢çš„一些方"
"法æ¥è¿”å›žé‚£ä¸ªæ ‡è¯†ç¬¦ï¼‰ï¼š "
#. Tag: programlisting
#: tutorial.xml:786
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ else if (args[0].equals(\"addpersontoevent\")) {\n"
" Long eventId = mgr.createAndStoreEvent(\"My Event\", new Date"
"());\n"
" Long personId = mgr.createAndStorePerson(\"Foo\", \"Bar\");\n"
" mgr.addPersonToEvent(personId, eventId);\n"
" System.out.println(\"Added person \" + personId + \" to event \" "
"+ eventId);\n"
" }]]>"
msgstr ""
"else if (args[0].equals(\"addpersontoevent\")) {\n"
" Long eventId = mgr.createAndStoreEvent(\"My Event\", new Date());\n"
" Long personId = mgr.createAndStorePerson(\"Foo\", \"Bar\");\n"
" mgr.addPersonToEvent(personId, eventId);\n"
" System.out.println(\"Added person \" + personId + \" to event \" + "
"eventId);\n"
"}"
#. Tag: para
#: tutorial.xml:788
#, no-c-format
msgid ""
"This is an example of an association between two equally important classes : "
"two entities. As mentioned earlier, there are other classes and types in a "
"typical model, usually \"less important\". Some you have already seen, like "
"an <literal>int or a java.lang.String. We "
"call these classes <emphasis>value types, and their instances "
"<emphasis>depend on a particular entity. Instances of these types "
"do not have their own identity, nor are they shared between entities. Two "
"persons do not reference the same <literal>firstname object, even "
"if they have the same first name. Value types cannot only be found in the "
"JDK , but you can also write dependent classes yourself such as an "
"<literal>Address or MonetaryAmount class. In "
"fact, in a Hibernate application all JDK classes are considered value types."
msgstr ""
"上é¢æ˜¯ä¸ªå…³äºŽä¸¤ä¸ªåŒç‰é‡è¦çš„实体类间关è”的例å。åƒå‰é¢æ‰€æåˆ°çš„é‚£æ ·ï¼Œåœ¨ç‰¹å®šçš„æ¨¡"
"åž‹ä¸ä¹Ÿå˜åœ¨å…¶å®ƒçš„类和类型,这些类和类型通常是“次è¦çš„â€ã€‚ä½ å·²çœ‹åˆ°è¿‡å…¶ä¸çš„一些,"
"åƒ <literal>int 或 String。我们称这些类为"
"<emphasis>值类型(value type),它们的实例ä¾èµ–(depend)"
"</emphasis>在æŸä¸ªç‰¹å®šçš„å®žä½“ä¸Šã€‚è¿™äº›ç±»åž‹çš„å®žä¾‹æ²¡æœ‰å®ƒä»¬è‡ªå·±çš„æ ‡è¯†ï¼ˆidentity),"
"也ä¸èƒ½åœ¨å®žä½“间被共享(比如,两个 person ä¸èƒ½å¼•ç”¨åŒä¸€ä¸ª <literal>firstname,"
"<literal>MonetaryAmount。 "
#. Tag: para
#: tutorial.xml:806
#, no-c-format
msgid ""
"You can also design a collection of value types. This is conceptually "
"different from a collection of references to other entities, but looks "
"almost the same in Java."
msgstr ""
"ä½ ä¹Ÿå¯ä»¥è®¾è®¡ä¸€ä¸ªå€¼ç±»åž‹çš„集åˆï¼Œè¿™åœ¨æ¦‚念上与引用其它实体的集åˆæœ‰å¾ˆå¤§çš„ä¸åŒï¼Œä½†"
"是在 Java 里é¢çœ‹èµ·æ¥å‡ ä¹Žæ˜¯ä¸€æ ·çš„ã€‚ "
#. Tag: title
#: tutorial.xml:815
#, no-c-format
msgid "Collection of values"
msgstr "值类型的集åˆ"
#. Tag: para
#: tutorial.xml:817
#, no-c-format
msgid ""
"Let's add a collection of email addresses to the <literal>Person "
"entity. This will be represented as a <interfacename>java.util.Setjava.lang.String instances:"
msgstr ""
"让我们在 <literal>Person å®žä½“é‡Œæ·»åŠ ä¸€ä¸ªç”µå邮件的集åˆã€‚这将以 "
"<classname>java.lang.String 实例的 java.util.Set is as follows:"
msgstr "这个 <literal>Set çš„æ˜ å°„å¦‚ä¸‹ï¼š"
#. Tag: programlisting
#: tutorial.xml:829
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ "
msgstr ""
"<set name=\"emailAddresses\" table=\"PERSON_EMAIL_ADDR\">\n"
" <key column=\"PERSON_ID\"/>\n"
" <element type=\"string\" column=\"EMAIL_ADDR\"/>\n"
"</set>"
#. Tag: para
#: tutorial.xml:831
#, no-c-format
msgid ""
"The difference compared with the earlier mapping is the use of the "
"<literal>element part which tells Hibernate that the collection "
"does not contain references to another entity, but is rather a collection "
"whose elements are values types, here specifically of type <literal>string attribute of the set element defines the foreign-key column name in the "
"collection table. The <literal>column attribute in the "
"<literal>element element defines the column name where the email "
"address values will actually be stored."
msgstr ""
"比较这次和æ¤å‰æ˜ 射的差别,主è¦åœ¨äºŽ <literal>element 部分,这次并没"
"有包å«å¯¹å…¶å®ƒå®žä½“引用的集åˆï¼Œè€Œæ˜¯å…ƒç´ 类型为 <literal>String 的集åˆ"
"ï¼ˆåœ¨æ˜ å°„ä¸ä½¿ç”¨å°å†™çš„åå—â€string“是å‘ä½ è¡¨æ˜Žå®ƒæ˜¯ä¸€ä¸ª Hibernate çš„æ˜ å°„ç±»åž‹æˆ–è€…ç±»"
"型转æ¢å™¨ï¼‰ã€‚和之å‰ä¸€æ ·ï¼Œ<literal>set å…ƒç´ çš„ tablekey å…ƒç´ å®šä¹‰äº†åœ¨é›†åˆè¡¨"
"ä¸å¤–键的å—段å。<literal>element å…ƒç´ çš„ column "
"属性定义用于实际ä¿å˜ <literal>String 值的å—段å。 "
#. Tag: para
#: tutorial.xml:847
#, no-c-format
msgid "Here is the updated schema:"
msgstr "看一下修改åŽçš„æ•°æ®åº“ schema。 "
#. Tag: programlisting
#: tutorial.xml:851
#, fuzzy, no-c-format
msgid ""
"<![CDATA[\n"
" _____________ __________________\n"
" | | | | _____________\n"
" | EVENTS | | PERSON_EVENT | | | "
"___________________\n"
" |_____________| |__________________| | PERSON | "
"| |\n"
" | | | | |_____________| | "
"PERSON_EMAIL_ADDR |\n"
" | *EVENT_ID | <--> | *EVENT_ID | | | |"
"___________________|\n"
" | EVENT_DATE | | *PERSON_ID | <--> | *PERSON_ID | <--> | "
"*PERSON_ID |\n"
" | TITLE | |__________________| | AGE | | "
"*EMAIL_ADDR |\n"
" |_____________| | FIRSTNAME | |"
"___________________|\n"
" | LASTNAME |\n"
" |_____________|\n"
" ]]>"
msgstr ""
"_____________ __________________\n"
" | | | | _____________\n"
" | EVENTS | | PERSON_EVENT | | | "
"___________________\n"
" |_____________| |__________________| | PERSON | "
"| |\n"
" | | | | |_____________| | "
"PERSON_EMAIL_ADDR |\n"
" | *EVENT_ID | <--> | *EVENT_ID | | | |"
"___________________|\n"
" | EVENT_DATE | | *PERSON_ID | <--> | *PERSON_ID | <--"
"> | *PERSON_ID |\n"
" | TITLE | |__________________| | AGE | | "
"*EMAIL_ADDR |\n"
" |_____________| | FIRSTNAME | |"
"___________________|\n"
" | LASTNAME |\n"
" |_____________|"
#. Tag: para
#: tutorial.xml:853
#, no-c-format
msgid ""
"You can see that the primary key of the collection table is in fact a "
"composite key that uses both columns. This also implies that there cannot be "
"duplicate email addresses per person, which is exactly the semantics we need "
"for a set in Java."
msgstr ""
"ä½ å¯ä»¥çœ‹åˆ°é›†åˆè¡¨çš„主键实际上是个å¤åˆä¸»é”®ï¼ŒåŒæ—¶ä½¿ç”¨äº†ä¸¤ä¸ªå—段。这也暗示了对于"
"åŒä¸€ä¸ª person ä¸èƒ½æœ‰é‡å¤çš„ email 地å€ï¼Œè¿™æ£æ˜¯ Java 里é¢ä½¿ç”¨ Set 时候所需è¦çš„"
"è¯ä¹‰ï¼ˆSet é‡Œå…ƒç´ ä¸èƒ½é‡å¤ï¼‰ã€‚"
#. Tag: para
#: tutorial.xml:859
#, no-c-format
msgid ""
"You can now try to add elements to this collection, just like we did before "
"by linking persons and events. It is the same code in Java:"
msgstr ""
"ä½ çŽ°åœ¨å¯ä»¥è¯•ç€æŠŠå…ƒç´ åŠ å…¥åˆ°è¿™ä¸ªé›†åˆï¼Œå°±åƒæˆ‘们在之å‰å…³è” person å’Œ event çš„é‚£"
"æ ·ã€‚å…¶å®žçŽ°çš„ Java 代ç 是相åŒçš„: "
#. Tag: programlisting
#: tutorial.xml:864
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private void addEmailToPerson(Long personId, String "
"emailAddress) {\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
"\n"
" Person aPerson = (Person) session.load(Person.class, personId);\n"
" // adding to the emailAddress collection might trigger a lazy load "
"of the collection\n"
" aPerson.getEmailAddresses().add(emailAddress);\n"
"\n"
" session.getTransaction().commit();\n"
" }]]>"
msgstr ""
"private void addEmailToPerson(Long personId, String emailAddress) {\n"
"\n"
" Session session = HibernateUtil.getSessionFactory().getCurrentSession"
"();\n"
" session.beginTransaction();\n"
"\n"
" Person aPerson = (Person) session.load(Person.class, personId);\n"
"\n"
" // The getEmailAddresses() might trigger a lazy load of the collection\n"
" aPerson.getEmailAddresses().add(emailAddress);\n"
"\n"
" session.getTransaction().commit();\n"
"}"
#. Tag: para
#: tutorial.xml:866
#, no-c-format
msgid ""
"This time we did not use a <emphasis>fetch query to initialize "
"the collection. Monitor the SQL log and try to optimize this with an eager "
"fetch."
msgstr ""
"这次我们没有使用 <emphasis>fetch 查询æ¥åˆå§‹åŒ–集åˆã€‚å› æ¤ï¼Œè°ƒç”¨å…¶ "
"getter 方法会触å‘å¦ä¸€é™„åŠ çš„ select æ¥åˆå§‹åŒ–集åˆï¼Œè¿™æ ·æˆ‘们æ‰èƒ½æŠŠå…ƒç´ æ·»åŠ è¿›åŽ»ã€‚"
"检查 SQL log,试ç€é€šè¿‡é¢„先抓å–æ¥ä¼˜åŒ–它。 "
#. Tag: title
#: tutorial.xml:875
#, no-c-format
msgid "Bi-directional associations"
msgstr "åŒå‘å…³è”"
#. Tag: para
#: tutorial.xml:877
#, no-c-format
msgid ""
"Next you will map a bi-directional association. You will make the "
"association between person and event work from both sides in Java. The "
"database schema does not change, so you will still have many-to-many "
"multiplicity."
msgstr ""
"接下æ¥æˆ‘ä»¬å°†æ˜ å°„åŒå‘å…³è”(bi-directional association)— 在 Java 里让 person "
"å’Œ event å¯ä»¥ä»Žå…³è”的任何一端访问å¦ä¸€ç«¯ã€‚当然,数æ®åº“ schema 没有改å˜ï¼Œæˆ‘们ä»"
"然需è¦å¤šå¯¹å¤šçš„阶数。一个关系型数æ®åº“è¦æ¯”网络编程è¯è¨€æ›´åŠ çµæ´»ï¼Œæ‰€ä»¥å®ƒå¹¶ä¸éœ€è¦"
"任何åƒå¯¼èˆªæ–¹å‘(navigation direction)的东西 — æ•°æ®å¯ä»¥ç”¨ä»»ä½•å¯èƒ½çš„æ–¹å¼è¿›è¡ŒæŸ¥"
"看和获å–。 "
#. Tag: para
#: tutorial.xml:885
#, no-c-format
msgid ""
"A relational database is more flexible than a network programming language, "
"in that it does not need a navigation direction; data can be viewed and "
"retrieved in any possible way."
msgstr ""
"关系型数æ®åº“比网络编程è¯è¨€æ›´ä¸ºçµæ´»ï¼Œå› 为它ä¸éœ€è¦æ–¹å‘导航,其数æ®å¯ä»¥ç”¨ä»»ä½•å¯"
"能的方å¼è¿›è¡ŒæŸ¥çœ‹å’Œæå–。"
#. Tag: para
#: tutorial.xml:893
#, no-c-format
msgid ""
"First, add a collection of participants to the <literal>Event "
"class:"
msgstr ""
"首先,把一个å‚与者(person)的集åˆåŠ å…¥ <literal>Event ç±»ä¸ï¼š "
#. Tag: programlisting
#: tutorial.xml:898
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private Set participants = new HashSet();\n"
"\n"
" public Set getParticipants() {\n"
" return participants;\n"
" }\n"
"\n"
" public void setParticipants(Set participants) {\n"
" this.participants = participants;\n"
" }]]>"
msgstr ""
"private Set participants = new HashSet();\n"
"\n"
"public Set getParticipants() {\n"
" return participants;\n"
"}\n"
"\n"
"public void setParticipants(Set participants) {\n"
" this.participants = participants;\n"
"}"
#. Tag: para
#: tutorial.xml:900
#, no-c-format
msgid ""
"Now map this side of the association in <literal>Event.hbm.xml."
msgstr "在 <literal>Event.hbm.xml 里é¢ä¹Ÿæ˜ 射这个关è”。 "
#. Tag: programlisting
#: tutorial.xml:904
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ "
msgstr ""
"<set name=\"participants\" table=\"PERSON_EVENT\" inverse=\"true\">\n"
" <key column=\"EVENT_ID\"/>\n"
" <many-to-many column=\"PERSON_ID\" class=\"events.Person\"/>\n"
"</set>"
#. Tag: para
#: tutorial.xml:906
#, no-c-format
msgid ""
"These are normal <literal>set mappings in both mapping documents. "
"Notice that the column names in <literal>key and many-to-"
"many</literal> swap in both mapping documents. The most important addition "
"here is the <literal>inverse=\"true\" attribute in the "
"<literal>set element of the Event's collection "
"mapping."
msgstr ""
"å¦‚ä½ æ‰€è§ï¼Œä¸¤ä¸ªæ˜ 射文件里都有普通的 <literal>set æ˜ å°„ã€‚æ³¨æ„åœ¨ä¸¤ä¸ªæ˜ "
"射文件ä¸ï¼Œäº’æ¢äº† <literal>key å’Œ many-to-many çš„"
"å—段å。这里最é‡è¦çš„是 <literal>Event æ˜ å°„æ–‡ä»¶é‡Œå¢žåŠ äº† "
"<literal>set å…ƒç´ çš„ inverse=\"true\" 属性。 "
#. Tag: para
#: tutorial.xml:914
#, no-c-format
msgid ""
"What this means is that Hibernate should take the other side, the "
"<literal>Person class, when it needs to find out information about "
"the link between the two. This will be a lot easier to understand once you "
"see how the bi-directional link between our two entities is created."
msgstr ""
"è¿™æ„味ç€åœ¨éœ€è¦çš„时候,Hibernate 能在关è”çš„å¦ä¸€ç«¯ — <literal>Person "
"类得到两个实体间关è”çš„ä¿¡æ¯ã€‚这将会æžå¤§åœ°å¸®åŠ©ä½ ç†è§£åŒå‘å…³è”是如何在两个实体间"
"被创建的。 "
#. Tag: title
#: tutorial.xml:923
#, no-c-format
msgid "Working bi-directional links"
msgstr "使åŒå‘è¿žèµ·æ¥"
#. Tag: para
#: tutorial.xml:925
#, no-c-format
msgid ""
"First, keep in mind that Hibernate does not affect normal Java semantics. "
"How did we create a link between a <literal>Person and an "
"<literal>Event in the unidirectional example? You add an instance "
"of <literal>Event to the collection of event references, of an "
"instance of <literal>Person. If you want to make this link bi-"
"directional, you have to do the same on the other side by adding a "
"<literal>Person reference to the collection in an Event å’Œ Event 之间创建è”系的?我"
"们把 <literal>Event å®žä¾‹æ·»åŠ åˆ° Person 实例内的 "
"event 引用集åˆé‡Œã€‚å› æ¤å¾ˆæ˜¾ç„¶ï¼Œå¦‚果我们è¦è®©è¿™ä¸ªå…³è”å¯ä»¥åŒå‘地工作,我们需è¦åœ¨"
"å¦å¤–一端åšåŒæ ·çš„事情 ï¼ æŠŠ <literal>Person å®žä¾‹åŠ å…¥ "
"<literal>Event 类内的 Person 引用集åˆã€‚这“在关è”的两端设置è”ç³»â€æ˜¯å®Œ"
"全必è¦çš„è€Œä¸”ä½ éƒ½å¾—è¿™ä¹ˆåšã€‚ "
#. Tag: para
#: tutorial.xml:935
#, no-c-format
msgid ""
"Many developers program defensively and create link management methods to "
"correctly set both sides (for example, in <literal>Person):"
msgstr ""
"许多开å‘人员防御å¼åœ°ç¼–程,创建管ç†å…³è”的方法æ¥ä¿è¯æ£ç¡®çš„设置了关è”的两端,比"
"如在 <literal>Person 里: "
#. Tag: programlisting
#: tutorial.xml:940
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ protected Set getEvents() {\n"
" return events;\n"
" }\n"
"\n"
" protected void setEvents(Set events) {\n"
" this.events = events;\n"
" }\n"
"\n"
" public void addToEvent(Event event) {\n"
" this.getEvents().add(event);\n"
" event.getParticipants().add(this);\n"
" }\n"
"\n"
" public void removeFromEvent(Event event) {\n"
" this.getEvents().remove(event);\n"
" event.getParticipants().remove(this);\n"
" }]]>"
msgstr ""
"protected Set getEvents() {\n"
" return events;\n"
"}\n"
"\n"
"protected void setEvents(Set events) {\n"
" this.events = events;\n"
"}\n"
"\n"
"public void addToEvent(Event event) {\n"
" this.getEvents().add(event);\n"
" event.getParticipants().add(this);\n"
"}\n"
"\n"
"public void removeFromEvent(Event event) {\n"
" this.getEvents().remove(event);\n"
" event.getParticipants().remove(this);\n"
"}"
#. Tag: para
#: tutorial.xml:942
#, no-c-format
msgid ""
"The get and set methods for the collection are now protected. This allows "
"classes in the same package and subclasses to still access the methods, but "
"prevents everybody else from altering the collections directly. Repeat the "
"steps for the collection on the other side."
msgstr ""
"注æ„现在对于集åˆçš„ get å’Œ set 方法的访问级别是 protected — è¿™å…许在ä½äºŽåŒä¸€ä¸ª"
"包(package)ä¸çš„类以åŠç»§æ‰¿è‡ªè¿™ä¸ªç±»çš„åç±»å¯ä»¥è®¿é—®è¿™äº›æ–¹æ³•ï¼Œä½†ç¦æ¢å…¶ä»–任何人的"
"直接访问,é¿å…了集åˆå†…å®¹çš„æ··ä¹±ã€‚ä½ åº”å°½å¯èƒ½åœ°åœ¨å¦ä¸€ç«¯ä¹ŸæŠŠé›†åˆçš„è®¿é—®çº§åˆ«è®¾æˆ "
"protected。 "
#. Tag: para
#: tutorial.xml:949
#, no-c-format
msgid ""
"What about the <literal>inverse mapping attribute? For you, and "
"for Java, a bi-directional link is simply a matter of setting the references "
"on both sides correctly. Hibernate, however, does not have enough "
"information to correctly arrange SQL <literal>INSERT and "
"<literal>UPDATE statements (to avoid constraint violations). "
"Making one side of the association <literal>inverse tells "
"Hibernate to consider it a <emphasis>mirror of the other side. "
"That is all that is necessary for Hibernate to resolve any issues that arise "
"when transforming a directional navigation model to a SQL database schema. "
"The rules are straightforward: all bi-directional associations need one side "
"as <literal>inverse. In a one-to-many association it has to be the "
"many-side, and in many-to-many association you can select either side."
msgstr ""
"<literal>inverse æ˜ å°„å±žæ€§ç©¶ç«Ÿè¡¨ç¤ºä»€ä¹ˆå‘¢ï¼Ÿå¯¹äºŽä½ å’Œ Java æ¥è¯´ï¼Œä¸€ä¸ªåŒ"
"å‘å…³è”仅仅是在两端简å•åœ°æ£ç¡®è®¾ç½®å¼•ç”¨ã€‚然而,Hibernate 并没有足够的信æ¯åŽ»æ£ç¡®"
"地执行 <literal>INSERT å’Œ UPDATE è¯å¥ï¼ˆä»¥é¿å…è¿"
"åæ•°æ®åº“约æŸï¼‰ï¼Œæ‰€ä»¥å®ƒéœ€è¦ä¸€äº›å¸®åŠ©æ¥æ£ç¡®çš„处ç†åŒå‘å…³è”。把关è”的一端设置为 "
"<literal>inverse 将告诉 Hibernate 忽略关è”的这一端,把这端看æˆæ˜¯å¦"
"外一端的一个<emphasis>镜象(mirror)。这就是所需的全部信æ¯ï¼Œ"
"Hibernate 利用这些信æ¯æ¥å¤„ç†æŠŠä¸€ä¸ªæœ‰å‘导航模型转移到数æ®åº“ schema 时的所有问"
"é¢˜ã€‚ä½ åªéœ€è¦è®°ä½è¿™ä¸ªç›´è§‚的规则:所有的åŒå‘å…³è”需è¦æœ‰ä¸€ç«¯è¢«è®¾ç½®ä¸º "
"<literal>inverse。在一对多关è”ä¸å®ƒå¿…须是代表多(many)的那端。而在"
"多对多(many-to-many)关è”ä¸ï¼Œä½ å¯ä»¥ä»»æ„选å–ä¸€ç«¯ï¼Œå› ä¸ºä¸¤ç«¯ä¹‹é—´å¹¶æ²¡æœ‰å·®åˆ«ã€‚ "
#. Tag: title
#: tutorial.xml:965
#, no-c-format
msgid "Part 3 - The EventManager web application"
msgstr "第三部分 - EventManager web 应用程åº"
#. Tag: para
#: tutorial.xml:967
#, no-c-format
msgid ""
"A Hibernate web application uses <literal>Session and "
"<literal>Transaction almost like a standalone application. "
"However, some common patterns are useful. You can now write an "
"<literal>EventManagerServlet. This servlet can list all events "
"stored in the database, and it provides an HTML form to enter new events."
msgstr ""
"Hibernate web 应用程åºä½¿ç”¨ <literal>Session å’Œ "
"<literal>Transaction çš„æ–¹å¼å‡ 乎和独立应用程åºæ˜¯ä¸€æ ·çš„。但是,有一些"
"常è§çš„模å¼ï¼ˆpattern)éžå¸¸æœ‰ç”¨ã€‚现在我们编写一个 "
"<literal>EventManagerServlet。这个 servlet å¯ä»¥åˆ—出数æ®åº“ä¸ä¿å˜çš„所"
"有的 events,还æ供一个 HTML 表å•æ¥å¢žåŠ æ–°çš„ events。 "
#. Tag: title
#: tutorial.xml:975
#, no-c-format
msgid "Writing the basic servlet"
msgstr "编写基本的 servlet"
#. Tag: para
#: tutorial.xml:977
#, no-c-format
msgid ""
"First we need create our basic processing servlet. Since our servlet only "
"handles HTTP <literal>GET requests, we will only implement the "
"<literal>doGet() method:"
msgstr ""
"这个 servlet åªå¤„ç† HTTP <literal>GET è¯·æ±‚ï¼Œå› æ¤ï¼Œæˆ‘们è¦å®žçŽ°çš„是 "
"<literal>doGet() 方法: "
#. Tag: programlisting
#: tutorial.xml:983
#, fuzzy, no-c-format
msgid ""
"<![CDATA[package org.hibernate.tutorial.web;\n"
"\n"
"// Imports\n"
"\n"
"public class EventManagerServlet extends HttpServlet {\n"
"\n"
" protected void doGet(\n"
" HttpServletRequest request,\n"
" HttpServletResponse response) throws ServletException, "
"IOException {\n"
"\n"
" SimpleDateFormat dateFormatter = new SimpleDateFormat( \"dd.MM.yyyy"
"\" );\n"
"\n"
" try {\n"
" // Begin unit of work\n"
" HibernateUtil.getSessionFactory().getCurrentSession()."
"beginTransaction();\n"
"\n"
" // Process request and render page...\n"
"\n"
" // End unit of work\n"
" HibernateUtil.getSessionFactory().getCurrentSession()."
"getTransaction().commit();\n"
" }\n"
" catch (Exception ex) {\n"
" HibernateUtil.getSessionFactory().getCurrentSession()."
"getTransaction().rollback();\n"
" if ( ServletException.class.isInstance( ex ) ) {\n"
" throw ( ServletException ) ex;\n"
" }\n"
" else {\n"
" throw new ServletException( ex );\n"
" }\n"
" }\n"
" }\n"
"\n"
"}]]>"
msgstr ""
"protected void doGet(HttpServletRequest request,\n"
" HttpServletResponse response)\n"
" throws ServletException, IOException {\n"
"\n"
" SimpleDateFormat dateFormatter = new SimpleDateFormat(\"dd.MM.yyyy\");\n"
"\n"
" try {\n"
" // Begin unit of work\n"
" HibernateUtil.getSessionFactory()\n"
" .getCurrentSession().beginTransaction();\n"
"\n"
" // Process request and render page...\n"
"\n"
" // End unit of work\n"
" HibernateUtil.getSessionFactory()\n"
" .getCurrentSession().getTransaction().commit();\n"
"\n"
" } catch (Exception ex) {\n"
" HibernateUtil.getSessionFactory()\n"
" .getCurrentSession().getTransaction().rollback();\n"
" throw new ServletException(ex);\n"
" }\n"
"\n"
"}"
#. Tag: para
#: tutorial.xml:985
#, no-c-format
msgid ""
"Save this servlet as <filename>src/main/java/org/hibernate/tutorial/web/"
"EventManagerServlet.java</filename>"
msgstr ""
"把这个 servlet ä¿å˜ä¸º <filename>src/main/java/org/hibernate/tutorial/web/"
"EventManagerServlet.java</filename>。"
#. Tag: para
#: tutorial.xml:990
#, no-c-format
msgid ""
"The pattern applied here is called <emphasis>session-per-request. "
"When a request hits the servlet, a new Hibernate <literal>Session "
"is opened through the first call to <literal>getCurrentSession() "
"on the <literal>SessionFactory. A database transaction is then "
"started. All data access occurs inside a transaction irrespective of whether "
"the data is read or written. Do not use the auto-commit mode in applications."
msgstr ""
"我们称这里应用的模å¼ä¸ºæ¯æ¬¡è¯·æ±‚一个 session<emphasis>(session-per-request)SessionFactorySession。然"
"åŽå¯åŠ¨ä¸€ä¸ªæ•°æ®åº“事务 — 所有的数æ®è®¿é—®éƒ½æ˜¯åœ¨äº‹åŠ¡ä¸è¿›è¡Œï¼Œä¸ç®¡æ˜¯è¯»è¿˜æ˜¯å†™ï¼ˆæˆ‘们在"
"应用程åºä¸ä¸ä½¿ç”¨ auto-commit 模å¼ï¼‰ã€‚ "
#. Tag: para
#: tutorial.xml:999
#, no-c-format
msgid ""
"Do <emphasis>not use a new Hibernate Session "
"for every database operation. Use one Hibernate <literal>Session "
"that is scoped to the whole request. Use <literal>getCurrentSession()为æ¯æ¬¡æ•°æ®åº“æ“作都使用一个新的 Hibernate "
"<literal>Session。将 Hibernate Session 的范围设"
"置为整个请求。è¦ç”¨ <literal>getCurrentSession()ï¼Œè¿™æ ·å®ƒè‡ªåŠ¨ä¼šç»‘å®šåˆ°"
"å½“å‰ Java 线程。"
#. Tag: para
#: tutorial.xml:1006
#, no-c-format
msgid ""
"Next, the possible actions of the request are processed and the response "
"HTML is rendered. We will get to that part soon."
msgstr ""
"下一æ¥ï¼Œå¯¹è¯·æ±‚çš„å¯èƒ½åŠ¨ä½œè¿›è¡Œå¤„ç†ï¼Œæ¸²æŸ“出å馈的 HTML。我们很快就会涉åŠåˆ°é‚£éƒ¨"
"分。 "
#. Tag: para
#: tutorial.xml:1011
#, no-c-format
msgid ""
"Finally, the unit of work ends when processing and rendering are complete. "
"If any problems occurred during processing or rendering, an exception will "
"be thrown and the database transaction rolled back. This completes the "
"<literal>session-per-request pattern. Instead of the transaction "
"demarcation code in every servlet, you could also write a servlet filter. "
"See the Hibernate website and Wiki for more information about this pattern "
"called <emphasis>Open Session in View. You will need it as soon "
"as you consider rendering your view in JSP, not in a servlet."
msgstr ""
"最åŽï¼Œå½“处ç†ä¸Žæ¸²æŸ“都结æŸçš„时候,这个工作å•å…ƒå°±ç»“æŸäº†ã€‚å‡è‹¥åœ¨å¤„ç†æˆ–渲染的时候"
"有任何错误å‘生,会抛出一个异常,回滚数æ®åº“äº‹åŠ¡ã€‚è¿™æ ·ï¼Œ<literal>session-per-"
"request</literal> 模å¼å°±å®Œæˆäº†ã€‚为了é¿å…在æ¯ä¸ª servlet ä¸éƒ½ç¼–写事务边界界定的"
"代ç ,å¯ä»¥è€ƒè™‘写一个 servlet 过滤器(filter)æ¥æ›´å¥½åœ°è§£å†³ã€‚关于这一模å¼çš„更多"
"ä¿¡æ¯ï¼Œè¯·å‚阅 Hibernate 网站和 Wiki,这一模å¼å«åš <emphasis>Open Session in "
"View</emphasis> — åªè¦ä½ 考虑用JSPæ¥æ¸²æŸ“ä½ çš„è§†å›¾ï¼ˆview),而ä¸æ˜¯åœ¨servletä¸ï¼Œ"
"ä½ å°±ä¼šå¾ˆå¿«ç”¨åˆ°å®ƒã€‚ "
#. Tag: title
#: tutorial.xml:1025
#, no-c-format
msgid "Processing and rendering"
msgstr "处ç†ä¸Žæ¸²æŸ“"
#. Tag: para
#: tutorial.xml:1027
#, no-c-format
msgid ""
"Now you can implement the processing of the request and the rendering of the "
"page."
msgstr "我们æ¥å®žçŽ°å¤„ç†è¯·æ±‚以åŠæ¸²æŸ“页é¢çš„工作。 "
#. Tag: programlisting
#: tutorial.xml:1031
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ // Write HTML header\n"
" PrintWriter out = response.getWriter();\n"
" out.println(\"<html>Event Manager"
"\");\n"
"\n"
" // Handle actions\n"
" if ( \"store\".equals(request.getParameter(\"action\")) ) {\n"
"\n"
" String eventTitle = request.getParameter(\"eventTitle\");\n"
" String eventDate = request.getParameter(\"eventDate\");\n"
"\n"
" if ( \"\".equals(eventTitle) || \"\".equals(eventDate) ) {\n"
" out.println(\"<b>Please enter event title and date.Added event.\");\n"
" }\n"
" }\n"
"\n"
" // Print page\n"
" printEventForm(out);\n"
" listEvents(out, dateFormatter);\n"
"\n"
" // Write HTML footer\n"
" out.println(\"</body>\");\n"
" out.flush();\n"
" out.close();]]>"
msgstr ""
"// Write HTML header\n"
"PrintWriter out = response.getWriter();\n"
"out.println(\"<html><head><title>Event Manager</"
"title></head><body>\");\n"
"\n"
"// Handle actions\n"
"if ( \"store\".equals(request.getParameter(\"action\")) ) {\n"
"\n"
" String eventTitle = request.getParameter(\"eventTitle\");\n"
" String eventDate = request.getParameter(\"eventDate\");\n"
"\n"
" if ( \"\".equals(eventTitle) || \"\".equals(eventDate) ) {\n"
" out.println(\"<b><i>Please enter event title and date."
"</i></b>\");\n"
" } else {\n"
" createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));\n"
" out.println(\"<b><i>Added event.</i></b>"
"\");\n"
" }\n"
"}\n"
"\n"
"// Print page\n"
"printEventForm(out);\n"
"listEvents(out, dateFormatter);\n"
"\n"
"// Write HTML footer\n"
"out.println(\"</body></html>\");\n"
"out.flush();\n"
"out.close();"
#. Tag: para
#: tutorial.xml:1033
#, no-c-format
msgid ""
"This coding style, with a mix of Java and HTML, would not scale in a more "
"complex application—keep in mind that we are only illustrating basic "
"Hibernate concepts in this tutorial. The code prints an HTML header and a "
"footer. Inside this page, an HTML form for event entry and a list of all "
"events in the database are printed. The first method is trivial and only "
"outputs HTML:"
msgstr ""
"必须承认,这ç§ç¼–ç é£Žæ ¼æŠŠ Java å’Œ HTML 混在一起,在更å¤æ‚的应用程åºé‡Œä¸åº”该大"
"é‡ä½¿ç”¨ — è®°ä½ï¼Œåœ¨æœ¬ç« 里我们仅仅是展示了 Hibernate 的基本概念。这段代ç 打å°å‡º"
"了 HTML 页眉和页脚,在这个页é¢é‡Œï¼Œè¿˜æ‰“å°äº†ä¸€ä¸ªè¾“å…¥ events æ¡ç›®çš„表å•å•å¹¶åˆ—出"
"了数æ®åº“里的有的 events。第一个方法微ä¸è¶³é“,仅仅是输出 HTML:"
#. Tag: programlisting
#: tutorial.xml:1042
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private void printEventForm(PrintWriter out) {\n"
" out.println(\"<h2>Add new event:\");\n"
" out.println(\"<form>\");\n"
" out.println(\"Title: <input name='eventTitle' length='50'/> "
"\");\n"
" out.println(\"Date (e.g. 24.12.2009): <input name='eventDate' "
"length='10'/><br/>\");\n"
" out.println(\"<input type='submit' name='action' value='store'/>"
"\");\n"
" out.println(\"</form>\");\n"
" }]]>"
msgstr ""
"private void printEventForm(PrintWriter out) {\n"
" out.println(\"<h2>Add new event:</h2>\");\n"
" out.println(\"<form>\");\n"
" out.println(\"Title: <input name='eventTitle' length='50'/><br/"
">\");\n"
" out.println(\"Date (e.g. 24.12.2009): <input name='eventDate' "
"length='10'/><br/>\");\n"
" out.println(\"<input type='submit' name='action' value='store'/>"
"\");\n"
" out.println(\"</form>\");\n"
"}"
#. Tag: para
#: tutorial.xml:1044
#, no-c-format
msgid ""
"The <literal>listEvents() method uses the Hibernate "
"<literal>Session bound to the current thread to execute a query:"
msgstr ""
"<literal>listEvents() 方法使用绑定到当å‰çº¿ç¨‹çš„ Hibernate "
"<literal>Session æ¥æ‰§è¡ŒæŸ¥è¯¢ï¼š"
#. Tag: programlisting
#: tutorial.xml:1050
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private void listEvents(PrintWriter out, SimpleDateFormat "
"dateFormatter) {\n"
"\n"
" List result = HibernateUtil.getSessionFactory()\n"
" .getCurrentSession().createCriteria(Event.class).list();\n"
" if (result.size() > 0) {\n"
" out.println(\"<h2>Events in database:\");\n"
" out.println(\"<table border='1'>\");\n"
" out.println(\"<tr>\");\n"
" out.println(\"<th>Event title\");\n"
" out.println(\"<th>Event date\");\n"
" out.println(\"</tr>\");\n"
" Iterator it = result.iterator();\n"
" while (it.hasNext()) {\n"
" Event event = (Event) it.next();\n"
" out.println(\"<tr>\");\n"
" out.println(\"<td>\" + event.getTitle() + \" |