|
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 Collection_Mapping.po to
# Xi HUANG <xhuang@redhat.com>, 2007, 2009, 2010.
msgid ""
msgstr ""
"Project-Id-Version: Collection_Mapping\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-20 21:02+0000\n"
"PO-Revision-Date: 2010-01-21 16:43+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 ""
#. 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 ""
#. Tag: para
#: tutorial.xml:54
#, no-c-format
msgid ""
"The distribution contains another example application under the "
"<filename>tutorial/eg project source directory."
msgstr ""
#. Tag: title
#: tutorial.xml:62
#, no-c-format
msgid "Part 1 - The first Hibernate Application"
msgstr "パート1 - 初めての 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 ""
"仮に小さなデータベースアプリケーションが必要だとしましょう。そのアプリケー"
"ションには出席したいイベントと、そのイベントのホストについての情報を格納する"
"ものとします。"
#. 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 ""
#. 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 ""
#. 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 ""
#. 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 ""
#. Tag: para
#: tutorial.xml:100
#, 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 ""
#. Tag: para
#: tutorial.xml:117
#, no-c-format
msgid ""
"Save this file as <filename>pom.xml in the project root directory."
msgstr ""
#. Tag: title
#: tutorial.xml:124
#, no-c-format
msgid "The first class"
msgstr "最初のクラス"
#. 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 "次にデータベースに格納するイベントを表すクラスを作成します。"
#. Tag: programlisting
#: tutorial.xml:131
#, fuzzy, 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 ""
"package events;\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
#, fuzzy, 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 ""
"ご覧のとおり、このクラスはフィールドが private の可視性を持っているのと同時"
"に、 JavaBean 標準のゲッター、セッターメソッドの命名規約に従っています。この"
"ような設計は推奨されていますが必須ではありません。アクセサメソッドを設けるの"
"はリファクタリングを考えた頑健性のためで、 Hibernate はフィールドに直接アクセ"
"スすることも可能です。引数のないコンストラクタは、リフレクションでこのクラス"
"のインスタンスを作成するために必要です。"
#. 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 ""
"<literal>id プロパティは、ある特定のイベントに対するユニークな識別"
"子の値を保持します。 Hibernate の完全な機能を使いたければ、すべての永続エン"
"ティティクラス (それほど重要ではない依存クラスというものもあります) にこの"
"ような識別子プロパティが必要になります。事実上ほとんどのアプリケーション "
"( 特に web アプリケーション) では、識別子でオブジェクトを区別する必要がある"
"ため、これは制限というよりも特徴であると考えるべきです。しかし通常オブジェク"
"トの ID を操作するようなことはしません。そのためセッターメソッドは private に"
"するべきです。 Hibernate だけがオブジェクトがセーブされたときに識別子へ値を代"
"入します。 Hibernate が(public, private, protected)フィールドに直接アクセス"
"できるのと同様に、 public, private, protected のアクセサメソッドにアクセスで"
"きるということがわかるでしょう。選択はあなたに任されているので、あなたのアプ"
"リケーションの設計に合わせることができます。"
#. 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 ""
"引数のないコンストラクタはすべての永続クラスに必須です。これは Hibernate が "
"Java のリフレクションを使って、オブジェクトを作成しなければならないためです。"
"コンストラクタを private にすることは可能ですが、実行時のプロキシ生成と、バイ"
"トコード操作なしの効率的なデータの抽出には、 package 可視性が必要です。"
#. Tag: para
#: tutorial.xml:164
#, no-c-format
msgid ""
"Save this file to the <filename>src/main/java/org/hibernate/tutorial/domain"
"filename> directory."
msgstr ""
#. Tag: title
#: tutorial.xml:171
#, no-c-format
msgid "The mapping file"
msgstr "マッピングファイル"
#. Tag: para
#: tutorial.xml:173
#, no-c-format
msgid ""
"Hibernate needs to know how to load and store objects of the persistent "
"class. This is where the Hibernate mapping file comes into play. The mapping "
"file tells Hibernate what table in the database it has to access, and what "
"columns in that table it should use."
msgstr ""
"Hibernate は、どのように永続クラスのオブジェクトをロードし格納すればよいかを"
"知る必要があります。ここで Hibernate マッピングファイルが登場します。マッピン"
"グファイルは、データベース内のどのテーブルにアクセスしなければならないか、そ"
"のテーブルのどのカラムを使うべきかを、 Hibernate に教えます。"
#. Tag: para
#: tutorial.xml:181
#, no-c-format
msgid "The basic structure of a mapping file looks like this:"
msgstr "マッピングファイルの基本的な構造はこのようになります:"
#. Tag: programlisting
#: tutorial.xml:185
#, fuzzy, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<?xml version=\"1.0\"?>\n"
"<!DOCTYPE hibernate-mapping PUBLIC\n"
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n"
" \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\n"
"\n"
"<hibernate-mapping>\n"
"[...]\n"
"</hibernate-mapping>"
#. 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 が非常に洗練されていることに注目してください。この DTD は、エ"
"ディタや IDE での XML マッピング要素と属性のオートコンプリーション機能に利用"
"できます。また DTD ファイルをテキストエディタで開けてみてください。というの"
"も、すべての要素と属性を概観し、コメントやデフォルトの値を見るには一番簡単な"
"方法だからです。 Hibernate は、 web から DTD ファイルをロードせずに、まずアプ"
"リケーションのクラスパスからこれを探し出そうとすることに注意してください。 "
"DTD ファイルは Hibernate ディストリビューションの <literal>src/ "
"ディレクトリと同様、<literal>hibernate3.jar にも含まれています。"
#. 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 宣言を省略します。当然ですがこれはオプ"
"ションではありません。"
#. 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 ""
"2つの <literal>hibernate-mapping タグの間に class"
"literal> 要素を含めてください。すべての永続エンティティクラス(念を押します"
"が、ファーストクラスのエンティティではない依存クラスというものが後ほど登場し"
"ます)は SQL データベース内のテーブルへのこのようなマッピングを必要とします。"
#. Tag: programlisting
#: tutorial.xml:213
#, fuzzy, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<hibernate-mapping>\n"
"\n"
" <class name=\"events.Event\" table=\"EVENTS\">\n"
"\n"
" </class>\n"
"\n"
"</hibernate-mapping>"
#. 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 ""
"これまで私たちは、 <literal>Event クラスのオブジェクトを "
"<literal>EVENTS テーブルに対して、どのように永続化したりロードした"
"りするのかを Hibernate に教えてきました。そして個々のインスタンスはテーブルの"
"行として表現されます。それでは引き続きテーブルの主キーに対するユニークな識別"
"子プロパティをマッピングしていきます。さらに、この識別子の扱いに気を使いたく"
"なかったのと同様に、代理の主キーカラムに対する Hibernate の識別子生成戦略を設"
"定します。"
#. Tag: programlisting
#: tutorial.xml:225
#, fuzzy, no-c-format
msgid ""
"<![CDATA["
msgstr ""
"<hibernate-mapping>\n"
"\n"
" <class name=\"events.Event\" table=\"EVENTS\">\n"
" <id name=\"id\" column=\"EVENT_ID\">\n"
" <generator class=\"native\"/>\n"
" </id>\n"
" </class>\n"
"\n"
"</hibernate-mapping>"
#. 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"
"literal> table holds the primary key value."
msgstr ""
#. 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 ""
#. Tag: para
#: tutorial.xml:249
#, no-c-format
msgid ""
"<literal>native is no longer consider the best strategy in terms "
"of portability. for further discussion, see"
msgstr ""
#. 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
#, fuzzy, 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 ""
"<hibernate-mapping>\n"
"\n"
" <class name=\"events.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 に教えます。この例では、 Hibernate は <literal>getDate()/setDate"
"()</literal> と 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>title"
"literal>, however, <literal>date is a reserved keyword in most "
"databases so you will need to map it to a different name."
msgstr ""
"なぜ <literal>date プロパティのマッピングには column"
"literal> 属性があり、 <literal>title プロパティにはないのでしょう"
"か? <literal>column 属性がなければ、 Hibernate はデフォルトでプロ"
"パティ名をカラム名として使います。これは <literal>title では上手く"
"いきます。しかし <literal>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"
"literal> column. Full date and time information is preserved by mapping the "
"property with a <literal>timestamp converter."
msgstr ""
"次に興味深いのは <literal>title マッピングが type"
"literal> 属性をも欠いている点です。マッピングファイルで宣言して使う type は、"
"おわかりかもしれませんが Java のデータ型ではありません。 SQL データベースの型"
"でもありません。これは <emphasis>Hibernateマッピング型 と呼ばれ"
"る、 Java から SQL データの型へまたは SQL から Java データ型へ翻訳するコン"
"バータです。繰り返しになりますが、 Hibernate は <literal>type 属性"
"がマッピングファイル内になければ、正しいコンバージョンとマッピング型を自分で"
"解決しようとします。 (Javaクラスのリフレクションを使った)この自動検知は、場"
"合によってはあなたが期待または必要とするデフォルト値にならないかもしれませ"
"ん。 <literal>date プロパティの場合がそうでした。 Hibernate はこの"
"( <literal>java.util.Date の)プロパティを SQL の date"
"literal> , <literal>timestamp , time のうち、ど"
"のカラムにマッピングするべきなのかわかりません。 <literal>timestamp"
"literal> コンバータでプロパティをマッピングすることにより、完全な日時を保存し"
"ます。"
#. Tag: para
#: tutorial.xml:300
#, no-c-format
msgid ""
"Hibernate makes this mapping type determination using reflection when the "
"mapping files are processed. This can take time and resources, so if startup "
"performance is important you should consider explicitly defining the type to "
"use."
msgstr ""
#. Tag: para
#: tutorial.xml:307
#, no-c-format
msgid ""
"Save this mapping file as <filename>src/main/resources/org/hibernate/"
"tutorial/domain/Event.hbm.xml</filename>."
msgstr ""
#. Tag: title
#: tutorial.xml:315
#, no-c-format
msgid "Hibernate configuration"
msgstr "Hibernate の設定"
#. Tag: para
#: tutorial.xml:317
#, no-c-format
msgid ""
"At this point, you should have the persistent class and its mapping file in "
"place. It is now time to configure Hibernate. First let's set up HSQLDB to "
"run in \"server mode\""
msgstr ""
#. Tag: para
#: tutorial.xml:324
#, no-c-format
msgid "We do this do that the data remains between runs."
msgstr ""
#. Tag: para
#: tutorial.xml:329
#, fuzzy, no-c-format
msgid ""
"We will utilize the Maven exec plugin to launch the HSQLDB server by "
"running: <command> mvn exec:java -Dexec.mainClass=\"org.hsqldb.Server\" -"
"Dexec.args=\"-database.0 file:target/data/tutorial\"</command> You will see "
"it start up and bind to a TCP/IP socket; this is where our application will "
"connect later. If you want to start with a fresh database during this "
"tutorial, shutdown HSQLDB, delete all files in the <filename>target/data"
"filename> directory, and start HSQLDB again."
msgstr ""
"<literal>data というディレクトリを開発ディレクトリのルートに作成し"
"てください。 HSQL DB はここにデータファイルを格納します。このデータディレクト"
"リにおいて <literal>java -classpath ../lib/hsqldb.jar org.hsqldb.Server"
"literal> を実行し、データベースを起動させてください。動作の開始と、 TCP/IP ソ"
"ケットのバインドが確認できます。後ほど作成するアプリケーションはここに接続し"
"ます。もしこのチュートリアル中にデータベースを初期化したければ、 HSQL DB を"
"シャットダウンして(作業ウィンドウで <literal>CTRL + C を押しま"
"す) <literal>data/ ディレクトリ内のファイルを全て消去した後、 "
"HSQL DB を再起動します。"
#. 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 ""
#. 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 ""
#. 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.xml"
"literal> file, or even complete programmatic setup. Most users prefer the "
"XML configuration file:"
msgstr ""
"Hibernate の設定では、単純な <literal>hibernate.properties ファイ"
"ル、それより少し洗練されている <literal>hibernate.cfg.xml ファイ"
"ル、または完全にプログラム上でセットアップする方法が利用できます。ほとんどの"
"ユーザーが好むのは XML 設定ファイルです:"
#. Tag: programlisting
#: tutorial.xml:363
#, fuzzy, no-c-format
msgid ""
"<![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"
"property>\n"
"\n"
" <!-- Enable Hibernate's automatic session context management -->\n"
" <property name=\"current_session_context_class\">thread\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 ""
"<?xml version='1.0' encoding='utf-8'?>\n"
"<!DOCTYPE hibernate-configuration PUBLIC\n"
" \"-//Hibernate/Hibernate Configuration DTD 3.0//EN\"\n"
" \"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
"\">\n"
"\n"
"<hibernate-configuration>\n"
"\n"
" <session-factory>\n"
"\n"
" <!-- Database connection settings -->\n"
" <property name=\"connection.driver_class\">org.hsqldb."
"jdbcDriver</property>\n"
" <property name=\"connection.url\">jdbc:hsqldb:hsql://"
"localhost</property>\n"
" <property name=\"connection.username\">sa</property>\n"
" <property name=\"connection.password\"></property>\n"
"\n"
" <!-- JDBC connection pool (use the built-in) -->\n"
" <property name=\"connection.pool_size\">1</property>\n"
"\n"
" <!-- SQL dialect -->\n"
" <property name=\"dialect\">org.hibernate.dialect."
"HSQLDialect</property>\n"
"\n"
" <!-- Enable Hibernate's automatic session context management --"
">\n"
" <property name=\"current_session_context_class\">thread</"
"property>\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</property>\n"
"\n"
" <!-- Drop and re-create the database schema on startup -->\n"
" <property name=\"hbm2ddl.auto\">create</property>\n"
"\n"
" <mapping resource=\"events/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 "この XML の設定が異なる 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 ""
"特定のデータベースを受け持つグローバルファクトリである Hibernate の "
"<literal>SessionFactory を設定します。もし複数のデータベースがある"
"場合には、 (スタートアップを簡単にするため)通常いくつかの設定ファイル内で、"
"いくつかの <literal><session-factory> を使う設定にしてくださ"
"い。"
#. 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"
"literal> element specifies the particular SQL variant Hibernate generates."
msgstr ""
"最初の4つの <literal>property 要素は JDBC コネクションに必要な設定"
"を含んでいます。 dialect という名前の <literal>property 要素は、 "
"Hibernate が生成する特定の SQL 方言を指定します。"
#. Tag: para
#: tutorial.xml:383
#, 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 ""
#. 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 ""
"永続的なコンテキストに対する Hibernate のセッションの自動管理は、後の例ですぐ"
"にわかるように、役に立つことでしょう。 <literal>hbm2ddl.auto オプ"
"ションはデータベーススキーマの自動生成を on にします。これは直接データベース"
"に対して生成されます。当然(config オプションを削除して) off にしたり、 "
"<literal>SchemaExport という Ant タスクの助けを借りてファイルにリダ"
"イレクトしたりできます。最後に永続クラスのためのマッピングファイルを設定に追"
"加します。"
#. 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 ""
#. 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 ""
#. 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.SessionFactory"
"interfacename> is used to obtain <interfacename>org.hibernate.Session"
"interfacename> instances. A <interfacename>org.hibernate.Session"
"interfacename> represents a single-threaded unit of work. The "
"<interfacename>org.hibernate.SessionFactory is a thread-safe "
"global object that is instantiated once."
msgstr ""
"さて <literal>Event オブジェクトをロードしたり格納したりする準備が"
"できました。しかしまずはインフラストラクチャのコードを書いて、セットアップを"
"完了する必要があります。まずは Hibernate をスタートアップしなければなりませ"
"ん。このスタートアップには、グローバルの <literal>SessionFactory オ"
"ブジェクトを生成して、それをアプリケーションのコードでアクセスしやすい場所に"
"格納することが含まれます。 <interfacename>org.hibernate.SessionFactory"
"interfacename> は新しく <interfacename>org.hibernate.Session "
"をオープンすることができます。 <interfacename>org.hibernate.Session"
"interfacename> はシングルスレッドの作業単位(Unit of Work)を表現します。それに"
"対し <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 ""
"ここでスタートアップを行い、便利に <interfacename>org.hibernate."
"SessionFactory</interfacename> へアクセスする HibernateUtil"
"literal> ヘルパクラスを作成します。実装を見てみましょう:"
#. Tag: programlisting
#: tutorial.xml:445
#, fuzzy, no-c-format
msgid ""
"<![CDATA[package org.hibernate.tutorial.util;\n"
"\n"
"import org.hibernate.SessionFactory;\n"
"import org.hibernate.cfg.Configuration;\n"
"\n"
"public class HibernateUtil {\n"
"\n"
" private static final SessionFactory sessionFactory = buildSessionFactory"
"();\n"
"\n"
" private static SessionFactory buildSessionFactory() {\n"
" try {\n"
" // Create the SessionFactory from hibernate.cfg.xml\n"
" return new Configuration().configure().buildSessionFactory();\n"
" }\n"
" catch (Throwable ex) {\n"
" // Make sure you log the exception, as it might be swallowed\n"
" System.err.println(\"Initial SessionFactory creation failed.\" + "
"ex);\n"
" throw new ExceptionInInitializerError(ex);\n"
" }\n"
" }\n"
"\n"
" public static SessionFactory getSessionFactory() {\n"
" return sessionFactory;\n"
" }\n"
"\n"
"}]]>"
msgstr ""
"package util;\n"
"\n"
"import org.hibernate.*;\n"
"import org.hibernate.cfg.*;\n"
"\n"
"public class HibernateUtil {\n"
"\n"
" private static final SessionFactory sessionFactory;\n"
"\n"
" static {\n"
" try {\n"
" // Create the SessionFactory from hibernate.cfg.xml\n"
" sessionFactory = new Configuration().configure()."
"buildSessionFactory();\n"
" } catch (Throwable ex) {\n"
" // Make sure you log the exception, as it might be swallowed\n"
" System.err.println(\"Initial SessionFactory creation failed.\" + "
"ex);\n"
" throw new ExceptionInInitializerError(ex);\n"
" }\n"
" }\n"
"\n"
" public static SessionFactory getSessionFactory() {\n"
" return sessionFactory;\n"
" }\n"
"\n"
"}"
#. Tag: para
#: tutorial.xml:447
#, no-c-format
msgid ""
"Save this code as <filename>src/main/java/org/hibernate/tutorial/util/"
"HibernateUtil.java</filename>"
msgstr ""
#. Tag: para
#: tutorial.xml:452
#, fuzzy, no-c-format
msgid ""
"This class not only produces the global <interfacename>org.hibernate."
"SessionFactory</interfacename> reference in its static initializer; it also "
"hides the fact that it uses a static singleton. We might just as well have "
"looked up the <interfacename>org.hibernate.SessionFactory "
"reference from JNDI in an application server or any other location for that "
"matter."
msgstr ""
"このクラスは静的初期化ブロック(クラスがロードされるときに JVM によって一度だ"
"け呼ばれる) でグローバルの <interfacename>org.hibernate.SessionFactory"
"interfacename> を生成するだけではなく、静的シングルトンの使用を隠蔽します。ア"
"プリケーションサーバーの JNDI から <interfacename>org.hibernate."
"SessionFactory</interfacename> をルックアップするのと同様です。"
#. Tag: para
#: tutorial.xml:461
#, fuzzy, 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 "
"に名前を与えると、 Hibernate は <interfacename>org.hibernate.SessionFactory"
"interfacename> 構築後に JNDI に対しバインドを行おうとします。このコードを完全"
"に排除するためには、 JMX デプロイメントを利用して JMX を利用できるコンテナを"
"インスタンス化し、 <literal>HibernateService を JNDI へバインドする"
"こともできます。これらの高度なオプションは、 Hibernate のリファレンスドキュメ"
"ントで説明されています。"
#. Tag: para
#: tutorial.xml:470
#, fuzzy, 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 src"
"literal> directory, next to <literal>hibernate.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 ""
"これは問題なく再コンパイルできるはずです。最後にロギングシステムを設定する必"
"要があります。 Hibernate は commons logging を使うため、 Log4j と JDK 1.4 "
"logging の選択をする必要がありません。ほとんどの開発者が好むのは Log4j で"
"す。 Hibernate ディストリビューションの( <literal>etc/ ディレクト"
"リ)から <literal>log4j.properties をあなたの src"
"literal> ディレクトリ内の <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()"
"literal> method:"
msgstr ""
"ついにオブジェクトのロードと格納に Hibernate を使うことができます。 "
"<literal>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
#, fuzzy, no-c-format
msgid ""
"In <literal>createAndStoreEvent() we created a new Event"
"literal> object and handed it over to Hibernate. At that point, Hibernate "
"takes care of the SQL and executes an <literal>INSERT on the "
"database."
msgstr ""
"新しい <literal>Event オブジェクトを生成し、それを Hibernate に渡し"
"ます。 Hibernate が SQL を処理し、データベースで <literal>INSERT を"
"実行します。実行前にl <literal>Session と Transaction"
"literal> を処理するコードを確認してください。"
#. 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"
"interfacename> API. In this particular case we are using JDBC-based "
"transactional semantics, but it could also run with JTA."
msgstr ""
"<interface>org.hibernate.Session は1つの作業単位 (Unit of Work) "
"です。当分の間、話を簡単にするために、 <interface>org.hibernate.Session"
"interface> と <literal>Transaction の対応を一対一と仮定します。使用"
"しているトランザクションシステム(このケースでは JTA と共存できる単純な "
"JDBC)からコードを保護するために、 Hibernate <literal>Session 上で"
"利用可能な <interfacename>org.hibernate.Transaction API を使"
"用します。"
#. Tag: para
#: tutorial.xml:518
#, fuzzy, no-c-format
msgid ""
"What does <literal>sessionFactory.getCurrentSession() 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"
"interfacename> を取得し保持すれば ( <literal>HibernateUtil のおか"
"げで簡単です)、このメソッドを何度でも、どこからでも呼び出すことができます。 "
"<literal>getCurrentSession() メソッドは常に「現在の」作業単位(Unit "
"of Work)を返します。 <filename>src/main/resources/hibernate.cfg.xml"
"filename> のこの機能の設定で、\"thread\"を指定したことを思い出してください。"
"このため現在の作業単位のスコープは、このアプリケーションを実行する現在の "
"Java スレッドです。しかしこれで全てではありません。作業単位の開始時と終了時に"
"はスコープも考慮する必要があります。"
#. 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 ""
#. Tag: para
#: tutorial.xml:541
#, fuzzy, 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() を呼ぶと、新しい org."
"hibernate.Session</interface> を取得して新しい作業単位をスタートできます。こ"
"の <emphasis>thread-bound プログラミングモデルは、コードのフレキシ"
"ブルなレイヤリングを可能にするので、 Hibernate を利用する上で最も人気がありま"
"す (このチュートリアルで後ほど触れますがトランザクション境界コードはデータア"
"クセスコードとは区別されます)。"
#. 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"
"interface> for one operation. However this is pure coincidence; the example "
"is just not complex enough to show any other approach. The scope of a "
"Hibernate <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 ""
"作業単位 (Unit of Work) の範囲に関して、 Hibernate の <interface>org."
"hibernate.Session</interface> は1つまたはいくつかのデータベースオペレーション"
"を実行するために使用されるべきでしょうか?上記の例は、1つのオペレーションで1"
"つの <interface>org.hibernate.Session を使用します。これは純粋な"
"偶然で、例はその他のアプローチを示すほど込み入っていません。 Hibernate の "
"<interface>org.hibernate.Session の範囲は柔軟ですが、 "
"全ての</emphasis> データベースオペレーションのために新しい Hibernate "
"<interface>org.hibernate.Session を使用するようにアプリケーション"
"をデザインするべきではありません。従って、もしそれを以下の (普通の) 例で何度"
"か見たとしても、アンチパターンである <emphasis>オペレーション毎の Session"
"emphasis> を考慮してください。実際の (ウェブ) アプリケーションは、このチュー"
"トリアルで後に見ることができます。"
#. 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 ""
#. Tag: para
#: tutorial.xml:584
#, no-c-format
msgid "You may need to perform <command>mvn compile first."
msgstr ""
#. 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
#, fuzzy, no-c-format
msgid "This is the <literal>INSERT executed by Hibernate."
msgstr "HQL の <literal>INSERT 文の実行例です:"
#. Tag: para
#: tutorial.xml:600
#, fuzzy, no-c-format
msgid "To list stored events an option is added to the main method:"
msgstr ""
"それでは同じように格納されたイベントの一覧を見ようと思います。そのためメイン"
"メソッドにオプションを追加します:"
#. 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 ""
"ここですることは、データベースから存在するすべての <literal>Event "
"オブジェクトをロードする HQL (Hibernate Query Language) クエリを使うことで"
"す。 Hibernate は適切な SQL を生成し、それをデータベースに送り、そのデータを"
"使って <literal>Event オブジェクトを生成します。当然 HQL でさらに複"
"雑なクエリを作成できます。"
#. 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 ""
#. Tag: title
#: tutorial.xml:630
#, no-c-format
msgid "Part 2 - Mapping associations"
msgstr "パート2 - 関連のマッピング"
#. 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 ""
"永続エンティティクラスをテーブルにマッピングしました。さらにこの上にいくつか"
"のクラスの関連を追加しましょう。まず初めにアプリケーションに人々を追加し、彼"
"らが参加するイベントのリストを格納します。"
#. 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 ""
#. 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 ""
#. 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 ""
"それではこれら2つのエンティティ間の関連を作成します。人々がイベントに参加で"
"き、イベントが参加者を持つのは明らかです。扱わなければならない設計の問題は、"
"方向、多重度、コレクションの振る舞いです。"
#. Tag: title
#: tutorial.xml:676
#, no-c-format
msgid "A unidirectional Set-based association"
msgstr "単方向 Set ベース関連"
#. Tag: para
#: tutorial.xml:678
#, fuzzy, 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 クラスに追加します。こうし"
"ておくと、明示的なクエリ、つまりわざわざ <literal>aPerson.getEvents()"
"literal> を呼び出さずに、特定の人に紐付くイベントを簡単にナビゲートすることが"
"できます。私たちは Java のコレクション、<interfacename>java.util.Set"
"interfacename> を使います。コレクションは重複要素を持たないし、順番は私たちに"
"は意味がないからです。"
#. 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
#, fuzzy, 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()"
"</literal> のように、双方向にナビゲートしたければ、そうすることもできます。こ"
"れは機能的にみて必要ではありません。特定のイベントに関係するデータを取得する"
"明確なクエリを、いつでも実行することが出来ました。この設計の選択は開発者に任"
"されていて、この議論により明らかなのは関連の多重度です。つまり両側を「多」値"
"にする、 <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>set"
"literal> being most common. For a many-to-many association, or <emphasis>n:"
"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>column"
"literal> attribute of the <literal>many-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 エンティティリレーションシップ)には、関連テーブルが"
"必要です。このテーブルのそれぞれの行は、人とイベント間のリンクを表現します。"
"テーブル名は <literal>set 要素の table 属性で設"
"定します。人側の関連の識別子カラム名は <literal>key 要素で、イベン"
"ト側のカラム名は <literal>many-to-many の column"
"literal> 属性で定義します。 Hibernate にコレクションのオブジェクトのクラス "
"(正確には、参照のコレクションの反対側のクラス)を教えなければなりません。"
#. Tag: para
#: tutorial.xml:722
#, no-c-format
msgid "The database schema for this mapping is therefore:"
msgstr "そのためこのマッピングのデータベーススキーマは以下のようになります:"
#. 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 ""
"<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
#, fuzzy, 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()"
"literal>; Hibernate automatically detects that the collection has been "
"modified and needs to be updated. This is called <emphasis>automatic dirty "
"checking</emphasis>. You can also try it by modifying the name or the date "
"property of any of your objects. As long as they are in "
"<emphasis>persistent 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() や save() の明示的な呼"
"び出しはありません。 Hibernate は、修正されたことにより更新する必要のあるコレ"
"クションを自動的に検知します。これは <emphasis>自動ダーティチェック"
"emphasis> と呼ばれ、オブジェクトの名前や date プロパティを修正することで試す"
"ことも可能です。それらが <emphasis>永続 状態にある限り、つまり特定"
"の Hibernate <literal>Session にバインドされている限り (例えば作業"
"単位 (Unit of Work) の中で単にロードまたはセーブされた)、 Hibernate はどんな"
"変更もモニターし、遅延書き込み (write-behind) で SQL を実行します。通常、作業"
"単位 (Unit of Work) の最後にだけ行われるデータベースとメモリの状態を同期させ"
"る処理は、 <emphasis>フラッシュ と呼ばれます。このコードでは、作業"
"単位 (Unit of Work) はデータベーストランザクションのコミット(もしくはロール"
"バック)で終了します。これは、 <literal>CurrentSessionContext クラ"
"スに対して <literal>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 ""
"異なる作業単位 (Unit of Work) で人々とイベントをロードすることも当然できま"
"す。そうでなければ、永続状態にないとき(以前に永続であったなら、この状態を "
"<emphasis>分離(detached) と呼びます)、 org."
"hibernate.Session</interfacename> の外部でオブジェクトを修正します。分離され"
"るときにはコレクションを変更することも可能です:"
#. 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 の呼び出しは分離オブジェクトを再び永続化します。こ"
"れは、新しい作業単位 (Unit of Work) にバインドすると言えるでしょう。そのため"
"分離の間に加えられたどのような修正もデータベースにセーブできます。エンティ"
"ティオブジェクトのコレクションへの修正(追加・削除)も同様にセーブできます。"
#. 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 のメインメソッドに新しいアクションを追加して"
"コマンドラインから呼び出してみましょう。人やイベントの識別子が必要なら、 "
"<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 ""
"これは同じように重要な2つのクラス、つまり2つのエンティティ間の関連の例でし"
"た。前に述べたように、典型的なモデルには、普通「比較的重要ではない」他のクラ"
"スと型があります。これまでに見たような <literal>int や "
"<classname>java.lang.String のようなものです。このようなクラスを "
"<emphasis>値型 と言います。このインスタンスは特定のエンティティに "
"<emphasis>依存 します。この型のインスタンスは独自の ID を持ちませ"
"んし、エンティティ間で共有されることもありません (ファーストネームが同じだっ"
"たとしても、2人の人は同じ <literal>firstname オブジェクトを参照しま"
"せん)。値型はもちろん JDK 内に見つかりますが、それだけではなく (実際、 "
"Hibernate アプリケーションにおいてすべての JDK クラスは値型と見なせます)、 "
"例えば <literal>Address や 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.Set"
"interfacename> of <classname>java.lang.String instances:"
msgstr ""
#. Tag: programlisting
#: tutorial.xml:823
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ private Set emailAddresses = new HashSet();\n"
"\n"
" public Set getEmailAddresses() {\n"
" return emailAddresses;\n"
" }\n"
"\n"
" public void setEmailAddresses(Set emailAddresses) {\n"
" this.emailAddresses = emailAddresses;\n"
" }]]>"
msgstr ""
"private Set emailAddresses = new HashSet();\n"
"\n"
"public Set getEmailAddresses() {\n"
" return emailAddresses;\n"
"}\n"
"\n"
"public void setEmailAddresses(Set emailAddresses) {\n"
" this.emailAddresses = emailAddresses;\n"
"}"
#. Tag: para
#: tutorial.xml:825
#, no-c-format
msgid "The mapping of this <literal>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"
"literal>. The lowercase name tells you it is a Hibernate mapping type/"
"converter. Again the <literal>table attribute of the set"
"literal> element determines the table name for the collection. The "
"<literal>key 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 の部分ですが、 "
"Hibernate にこのコレクションが他のエンティティへの参照を含まず、 "
"<literal>string 型の要素のコレクションを含むことを教えます(小文字"
"の名前 (string) は Hibernate のマッピング型またはコンバータであるということで"
"す)。繰り返しますが、<literal>set 要素の table "
"属性は、コレクションのためのテーブル名を指定します。 <literal>key "
"要素はコレクションテーブルの外部キーカラム名を定義します。 <literal>element"
"literal> 要素の <literal>column 属性は string の"
"値が実際に格納されるカラムの名前を定義します。"
#. Tag: para
#: tutorial.xml:847
#, no-c-format
msgid "Here is the updated schema:"
msgstr "更新したスキーマを見てください:"
#. 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 ""
"コレクションテーブルの主キーは、実際は両方のカラムを使った複合キーであること"
"がわかります。これは人ごとに E メールアドレスが重複できないということで、 "
"Java の 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 ""
"以前人とイベントを関連づけたときと全く同じように、今や試しにコレクションに要"
"素を追加することができるようになりました。 両方とも 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
#, fuzzy, 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 のログ"
"を監視して、即時フェッチを使って最適化してください。"
#. 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 ""
"次に双方向関連をマッピングします。 Java で両側から人とイベントの関連を動作さ"
"せます。もちろん、データベーススキーマは変わりませんが、多重度は多対多のまま"
"です。"
#. 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 ""
"まず <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 ""
"ご覧のとおり、いずれのマッピングドキュメント (XMLファイル) でも、普通の "
"<literal>set マッピングを使っています。 key と "
"<literal>many-to-many のカラム名が、両方のマッピングドキュメントで"
"入れ替えになっていることに注目してください。ここで最も重要な追加項目は、 "
"<literal>Event のコレクションマッピングの set 要"
"素にある <literal>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 ""
"この指定の意味は、2つの間のエンティティ間のリンクについての情報を探す必要があ"
"るとき、 Hibernate は反対側のエンティティ、つまり <literal>Person "
"クラスから探すということです。一度2つのエンティティ間の双方向リンクがどのよう"
"に作成されるかがわかれば、これを理解することはとても簡単です。"
#. 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"
"literal>. This process of \"setting the link on both sides\" is absolutely "
"necessary with bi-directional links."
msgstr ""
"まず、 Hibernate が通常の Java のセマンティクスに影響を及ぼさないことを心に留"
"めておいてください。私たちは、単方向の例としてどのように <literal>Person"
"literal> と <literal>Event の間のリンクを作成したでしょうか? "
"<literal>Person のインスタンスのイベントへの参照のコレクションに "
"<literal>Event のインスタンスを追加しました。そのためこのリンクを双"
"方向にしたければ、当たり前ですが反対側にも同じことをしなければなりません。 "
"<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 ""
"コレクションのゲットとセットメソッドが現在 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 は(制約違反を避けるために) SQL の <literal>INSERT"
"literal> と <literal>UPDATE 文を正確に変更するための十分な情報を"
"持っていないので、双方向関連プロパティを扱うための何らかの助けを必要としま"
"す。関連の片側を <literal>inverse に設定することで、 Hibernate は基"
"本的には設定した側を無視し、反対側の <emphasis>鏡 として考えます。"
"これだけで、 Hibernate は方向を持つナビゲーションモデルを SQL データベースス"
"キーマへ変換するときのすべての問題にうまく対処できます。覚えておかなければな"
"らないルールは簡単です。双方向関連は必ず片側を <literal>inverse に"
"する必要があるということです。一対多関連ではそれは多側でなければなりません。"
"多対多関連ではどちら側でも構いません。どちらでも違いはありません。"
#. Tag: title
#: tutorial.xml:965
#, no-c-format
msgid "Part 3 - The EventManager web application"
msgstr "パート3 - 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 と Transaction を使用しま"
"す。しかしいくつかの一般的なパターンが役立ちます。ここで "
"<literal>EventManagerServlet を作成します。このサーブレットは、デー"
"タベースに格納した全てのイベントをリストにでき、さらに HTML フォームから新し"
"いイベントを入力できるものです。"
#. 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 ""
#. 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 ""
"これは <emphasis>session-per-request というパターンです。 Servlet "
"がリクエストを受け取ると、 <literal>SessionFactory の "
"<literal>getCurrentSession() の最初の呼び出しで、 Hibernate の新し"
"い <literal>Session が開かれます。そのときデータベーストランザク"
"ションが開始されます。データの読み書きに関わらず、すべてのデータアクセスはト"
"ランザクション内で行います(アプリケーション内ではオートコミットモードを使用"
"しません)。"
#. 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()"
"literal>, so that it is automatically bound to the current Java thread."
msgstr ""
"全てのデータベースオペレーションで新しい Hibernate <literal>Session"
"literal> を使用 <emphasis>しないでください 。全てのリクエストで機"
"能する、1つの Hibernate <literal>Session を使用してください。自動"
"的に現在の Java スレッドにバインドされるので、 <literal>getCurrentSession()"
"literal> を使用してください。"
#. 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 ""
"最後にリクエストの処理と HTML 描画が完了したときに、作業単位 (Unit of Work) "
"を終了します。もし処理や描画中に問題が発生した場合、例外が送出されててデータ"
"ベーストランザクションをロールバックします。これで <literal>session-per-"
"request</literal> パターンが完了します。全てのサーブレットにトランザクション"
"境界のコードを書く代わりに、サーブレットフィルタに記述することも可能です。 "
"<emphasis>Open Session in View と呼ばれるこのパターンについては、 "
"Hibernate の Web サイトや Wiki を参照してください。サーブレットではなく JSP "
"で HTML 描画をしようとすると、すぐにこのパターンについての情報が必要になるで"
"しょう。"
#. 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."
"b>\");\n"
" }\n"
" else {\n"
" createAndStoreEvent(eventTitle, dateFormatter.parse"
"(eventDate));\n"
" out.println(\"<b>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 の"
"ヘッダーとフッターの記述です。このページには、イベントを入力する HTML フォー"
"ムと、データベースにある全てのイベントのリストが表示されます。最初のメソッド"
"はごく単純な 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() + \" | \");\n"
" out.println(\"<td>\" + dateFormatter.format(event.getDate()) "
"+ \"</td>\");\n"
" out.println(\"</tr>\");\n"
" }\n"
" out.println(\"</table>\");\n"
" }\n"
" }]]>"
msgstr ""
"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:</h2>\");\n"
" out.println(\"<table border='1'>\");\n"
" out.println(\"<tr>\");\n"
" out.println(\"<th>Event title</th>\");\n"
" out.println(\"<th>Event date</th>\");\n"
" out.println(\"</tr>\");\n"
" for (Iterator it = result.iterator(); it.hasNext();) {\n"
" Event event = (Event) it.next();\n"
" out.println(\"<tr>\");\n"
" out.println(\"<td>\" + event.getTitle() + \"</td>"
"\");\n"
" out.println(\"<td>\" + dateFormatter.format(event.getDate"
"()) + \"</td>\");\n"
" out.println(\"</tr>\");\n"
" }\n"
" out.println(\"</table>\");\n"
" }\n"
"}"
#. Tag: para
#: tutorial.xml:1052
#, no-c-format
msgid ""
"Finally, the <literal>store action is dispatched to the "
"<literal>createAndStoreEvent() method, which also uses the "
"<literal>Session of the current thread:"
msgstr ""
"最後に、 <literal>store アクションが createAndStoreEvent()"
"</literal> メソッドを呼び出します。このメソッドでも現在のスレッドの "
"<literal>Session を利用します。"
#. Tag: programlisting
#: tutorial.xml:1058
#, fuzzy, no-c-format
msgid ""
"<![CDATA[ protected void createAndStoreEvent(String title, Date theDate) "
"{\n"
" Event theEvent = new Event();\n"
" theEvent.setTitle(title);\n"
" theEvent.setDate(theDate);\n"
"\n"
" HibernateUtil.getSessionFactory()\n"
" .getCurrentSession().save(theEvent);\n"
" }]]>"
msgstr ""
"protected void createAndStoreEvent(String title, Date theDate) {\n"
" Event theEvent = new Event();\n"
" theEvent.setTitle(title);\n"
" theEvent.setDate(theDate);\n"
"\n"
" HibernateUtil.getSessionFactory()\n"
" .getCurrentSession().save(theEvent);\n"
"}"
#. Tag: para
#: tutorial.xml:1060
#, no-c-format
msgid ""
"The servlet is now complete. A request to the servlet will be processed in a "
"single <literal>Session and Transaction. As "
"earlier in the standalone application, Hibernate can automatically bind "
"these objects to the current thread of execution. This gives you the freedom "
"to layer your code and access the <literal>SessionFactory in any "
"way you like. Usually you would use a more sophisticated design and move the "
"data access code into data access objects (the DAO pattern). See the "
"Hibernate Wiki for more examples."
msgstr ""
"これでサーブレットの完成です。サーブレットへのリクエストは、1つの "
"<literal>Session と Transaction で処理されるで"
"しょう。最初のスタンドアローンのアプリケーションのように、 Hibernate は自動的"
"にこれらのオブジェクトを実行するスレッドに結び付けることができます。これによ"
"り、開発者が自由にコードをレイヤー分けでき、好きな方法で "
"<literal>SessionFactory へのアクセスができるようになります。通常、"
"開発者はより洗練されたデザインを使用して、データアクセスのコードをデータアク"
"セスオブジェクトに移動するでしょう(DAOパターン)。より多くの例は、 "
"Hibernate の Wiki を参照してください。"
#. Tag: title
#: tutorial.xml:1074
#, no-c-format
msgid "Deploying and testing"
msgstr "デプロイとテスト"
#. Tag: para
#: tutorial.xml:1076
#, no-c-format
msgid ""
"To deploy this application for testing we must create a Web ARchive (WAR). "
"First we must define the WAR descriptor as <filename>src/main/webapp/WEB-INF/"
"web.xml</filename>"
msgstr ""
#. Tag: programlisting
#: tutorial.xml:1082
#, fuzzy, no-c-format
msgid ""
"<![CDATA[\n"
" <servlet-class>org.hibernate.tutorial.web.EventManagerServlet"
"servlet-class>\n"
" </servlet>\n"
"\n"
" <servlet-mapping>\n"
" <servlet-name>Event Manager\n"
" <url-pattern>/eventmanager\n"
" </servlet-mapping>\n"
"</web-app>]]>"
msgstr ""
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<web-app version=\"2.4\"\n"
" xmlns=\"http://java.sun.com/xml/ns/j2ee\"\n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee\n"
" http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd\">\n"
"\n"
" <servlet>\n"
" <servlet-name>Event Manager</servlet-name>\n"
" <servlet-class>events.EventManagerServlet</servlet-"
"class>\n"
" </servlet>\n"
"\n"
" <servlet-mapping>\n"
" <servlet-name>Event Manager</servlet-name>\n"
" <url-pattern>/eventmanager</url-pattern>\n"
" </servlet-mapping>\n"
"</web-app>"
#. Tag: para
#: tutorial.xml:1084
#, no-c-format
msgid ""
"To build and deploy call <literal>mvn package in your project "
"directory and copy the <filename>hibernate-tutorial.war file into "
"your Tomcat <filename>webapps directory."
msgstr ""
"ビルドとデプロイのために、プロジェクトディレクトリで <literal>mvn package"
"literal> を呼び出し、 <literal>hibernate-tutorial.war ファイルを "
"Tomcat の <literal>webapp ディレクトリにコピーしてください。"
#. Tag: para
#: tutorial.xml:1091
#, fuzzy, no-c-format
msgid ""
"If you do not have Tomcat installed, download it from <ulink url=\"http://"
"tomcat.apache.org/\"></ulink> and follow the installation instructions. Our "
"application requires no changes to the standard Tomcat configuration."
msgstr ""
"まだ Tomcat をインストールしていなければ、ダウンロードして、インストールガイ"
"ドに従ってください。しかし、このアプリケーションのデプロイするために、 "
"Tomcat の設定を変更する必要はありません。"
#. Tag: para
#: tutorial.xml:1099
#, no-c-format
msgid ""
"Once deployed and Tomcat is running, access the application at "
"<literal>http://localhost:8080/hibernate-tutorial/eventmanager. "
"Make sure you watch the Tomcat log to see Hibernate initialize when the "
"first request hits your servlet (the static initializer in "
"<literal>HibernateUtil is called) and to get the detailed output "
"if any exceptions occurs."
msgstr ""
"一度デプロイして Tomcat を起動すれば、 <literal>http://localhost:8080/"
"hibernate-tutorial/eventmanager</literal> でアプリケーションへのアクセスが可"
"能です。最初のリクエストが作成したサーブレットに渡ったときに、 Tomcat のログ"
"で Hibernate の初期化処理を確認してください ( <literal>HibernateUtil"
"literal> 内の静的初期化ブロックが呼ばれています)。また、例外が発生したなら詳"
"細を確認してください。"
#. Tag: title
#: tutorial.xml:1112
#, no-c-format
msgid "Summary"
msgstr "要約"
#. Tag: para
#: tutorial.xml:1114
#, no-c-format
msgid ""
"This tutorial covered the basics of writing a simple standalone Hibernate "
"application and a small web application. More tutorials are available from "
"the Hibernate <ulink url=\"http://hibernate.org\">website."
msgstr ""
"このチュートリアルでは、簡単なスタンドアローンの Hibernate アプリケーションと"
"小規模の Web アプリケーションを書くための基本を紹介しました。"
Other Hibernate examples (source code examples)
Here is a short list of links related to this Hibernate tutorial.po source code file: