⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorial.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 5 页
字号:
#. Tag: para#: tutorial.xml:110#, no-c-formatmsgid "In the next step, we tell Hibernate about this persistent class."msgstr "次のステップでは、Hibernateにこの永続クラスの情報を教えます。"#. Tag: title#: tutorial.xml:117#, no-c-formatmsgid "The mapping file"msgstr "マッピングファイル"#. Tag: para#: tutorial.xml:119#, no-c-formatmsgid """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:126#, no-c-formatmsgid "The basic structure of a mapping file looks like this:"msgstr "マッピングファイルの基本的な構造はこのようになります:"#. Tag: programlisting#: tutorial.xml:130#, no-c-formatmsgid """<![CDATA[<?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>]]>"msgstr ""#. Tag: para#: tutorial.xml:132#, no-c-formatmsgid """Note that the Hibernate DTD is very sophisticated. You can use it for auto-""completion of XML mapping elements and attributes in your editor or IDE. You ""also should open up the DTD file in your text editor - it's the easiest way ""to get an overview of all elements and attributes and to see the defaults, ""as well as some comments. Note that 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 <literal>hibernate3.jar</literal> as well as in ""the <literal>src/</literal> directory of the Hibernate distribution."msgstr """Hibernate DTDが非常に洗練されていることに注目してください。 このDTDは、エディ""タやIDEでのXMLマッピング要素と属性のオートコンプリーション機能に利用できま""す。 またDTDファイルをテキストエディタで開けてみてください。 というのも、すべ""ての要素と属性を概観し、 コメントやデフォルトの値を見るには一番簡単な方法だか""らです。 Hibernateは、webからDTDファイルをロードせずに、 まずアプリケーション""のクラスパスからこれを探し出そうとすることに注意してください。 DTDファイルは""Hibernateディストリビューションの <literal>src/</literal> ディレクトリと同""様、<literal>hibernate3.jar</literal> にも含まれています。"#. Tag: para#: tutorial.xml:143#, no-c-formatmsgid """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:148#, no-c-formatmsgid """Between the two <literal>hibernate-mapping</literal> tags, include a ""<literal>class</literal> element. All persistent entity classes (again, ""there might be dependent classes later on, which are not first-class ""entities) need such a mapping, to a table in the SQL database:"msgstr """2つの <literal>hibernate-mapping</literal> タグの間に <literal>class</""literal> 要素を含めてください。 すべての永続エンティティクラス(念を押します""が、 ファーストクラスのエンティティではない依存クラスというものが後ほど登場し""ます) はSQLデータベース内のテーブルへのこのようなマッピングを必要とします。"#. Tag: programlisting#: tutorial.xml:155#, no-c-formatmsgid """<![CDATA[<hibernate-mapping>\n""\n""    <class name=\"events.Event\" table=\"EVENTS\">\n""\n""    </class>\n""\n""</hibernate-mapping>]]>"msgstr ""#. Tag: para#: tutorial.xml:157#, no-c-formatmsgid """So far we told Hibernate how to persist and load object of class ""<literal>Event</literal> to the table <literal>EVENTS</literal>, each ""instance represented by a row in that table. Now we continue with a mapping ""of the unique identifier property to the tables primary key. In addition, as ""we don't want to care about handling this identifier, we configure ""Hibernate's identifier generation strategy for a surrogate primary key ""column:"msgstr """これまで私たちは、<literal>Event</literal> クラスのオブジェクトを ""<literal>EVENTS</literal> テーブルに対して、どのように永続化したりロードした""りするのかを Hibernateに教えてきました。そして個々のインスタンスはテーブルの""行として表現されます。 それでは引き続きテーブルの主キーに対するユニークな識別""子プロパティをマッピングしていきます。 さらに、この識別子の扱いに気を使いたく""なかったのと同様に、 代理の主キーカラムに対するHibernateの識別子生成戦略を設""定します。"#. Tag: programlisting#: tutorial.xml:165#, no-c-formatmsgid """<![CDATA[<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>]]>"msgstr ""#. Tag: para#: tutorial.xml:167#, no-c-formatmsgid """The <literal>id</literal> element is the declaration of the identifer ""property, <literal>name=\"id\"</literal> declares the name of the Java ""property - Hibernate will use the getter and setter methods to access the ""property. The column attribute tells Hibernate which column of the ""<literal>EVENTS</literal> table we use for this primary key. The nested ""<literal>generator</literal> element specifies the identifier generation ""strategy, in this case we used <literal>native</literal>, which picks the ""best strategy depending on the configured database (dialect). Hibernate ""supports database generated, globally unique, as well as application ""assigned identifiers (or any strategy you have written an extension for)."msgstr """<literal>id</literal> 要素は識別子プロパティの宣言であり、 <literal>name=\"id""\"</literal> でJavaプロパティの名前を宣言します。 Hibernateはこのプロパティへ""アクセスするためにゲッター、セッターメソッドを使います。 カラム属性では ""<literal>EVENTS</literal> テーブルのどのカラムを主キーとして使うのかを ""Hibernateに教えます。 入れ子になっている <literal>generator</literal> 要素""は、識別子を生成する時の戦略を指定します。 (この例では <literal>native</""literal> を用いました)。 この要素は、設定したデータベース(dialect)に対する""最良な識別子生成戦略を選定するものです。 Hibernateは、アプリケーションで値を""割り当てる戦略(もしくは独自に拡張した戦略)と同様に、 グローバルにユニークな""値をデータベースに生成させる戦略もサポートしています。"#. Tag: para#: tutorial.xml:180#, no-c-formatmsgid """Finally we include declarations for the persistent properties of the class ""in the mapping file. By default, no properties of the class are considered ""persistent:"msgstr """最後にクラスの永続プロパティの宣言をマッピングファイルに含めます。 デフォルト""では、クラスのプロパティは永続と見なされません:"#. Tag: programlisting#: tutorial.xml:186#, no-c-formatmsgid """<![CDATA[\n""<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>]]>"msgstr ""#. Tag: para#: tutorial.xml:188#, no-c-formatmsgid """Just as with the <literal>id</literal> element, the <literal>name</literal> ""attribute of the <literal>property</literal> element tells Hibernate which ""getter and setter methods to use. So, in this case, Hibernate will look for ""<literal>getDate()/setDate()</literal>, as well as <literal>getTitle()/""setTitle()</literal>."msgstr """<literal>id</literal> 要素の場合と同様に、 <literal>property</literal> 要素""の <literal>name</literal> 属性で、どのゲッターとセッターメソッドを使うべきか""をHibernateに教えます。 この例では、Hibernateは <literal>getDate()/setDate()""</literal> と <literal>getTitle()/setTitle()</literal> を 探します。"#. Tag: para#: tutorial.xml:195#, no-c-formatmsgid """Why does the <literal>date</literal> property mapping include the ""<literal>column</literal> attribute, but the <literal>title</literal> ""doesn't? Without the <literal>column</literal> attribute Hibernate by ""default uses the property name as the column name. This works fine for ""<literal>title</literal>. However, <literal>date</literal> is a reserved ""keyword in most database, so we better map it to a different name."msgstr """なぜ <literal>date</literal> プロパティのマッピングには <literal>column</""literal> 属性があり、<literal>title</literal> プロパティにはないのでしょう""か? <literal>column</literal> 属性がなければ、Hibernateはプロパティ名をカラ""ム名として使います。 これは <literal>title</literal> では上手く行きます。 し""かし <literal>date</literal> はほとんどのデータベースで予約語なので、 違う名""前でマッピングした方がよいのです。"#. Tag: para#: tutorial.xml:204#, no-c-formatmsgid """The next interesting thing is that the <literal>title</literal> mapping also ""lacks a <literal>type</literal> attribute. The types we declare and use in ""the mapping files are not, as you might expect, Java data types. They are ""also not SQL database types. These types are so called <emphasis>Hibernate ""mapping types</emphasis>, 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</literal> ""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</literal> ""property. Hibernate can't know if the property (which is of <literal>java.""util.Date</literal>) should map to a SQL <literal>date</literal>, ""<literal>timestamp</literal>, or <literal>time</literal> column. We preserve ""full date and time information by mapping the property with a ""<literal>timestamp</literal> converter."msgstr """次に興味深いのは <literal>title</literal> マッピングが <literal>type</""literal> 属性をも欠いている点です。 マッピングファイルで宣言して使うtypeは、""おわかりかもしれませんがJavaのデータ型ではありません。 SQLデータベースの型で""もありません。 これは <emphasis>Hibernateマッピング型</emphasis> と呼ばれ""る、 JavaからSQLデータの型へまたはSQLからJavaデータ型へ翻訳するコンバータで""す。 繰り返しになりますが、Hibernateは <literal>type</literal> 属性がマッピン""グファイル内になければ、 正しいコンバージョンとマッピング型を自分で解決しよう""とします。 (Javaクラスのリフレクションを使った)この自動検知は、 場合によっ""てはあなたが期待または必要とするデフォルト値にならないかもしれません。 ""<literal>date</literal> プロパティの場合がそうでした。 Hibernateはこの""( <literal>java.util.Date</literal> の)プロパティを SQLの <literal>date</""literal> , <literal>timestamp</literal> , <literal>time</literal> のうち、ど""のカラムにマッピングするべきなのかわかりません。 <literal>timestamp</""literal> コンバータでプロパティをマッピングすることにより、完全な日時を保存し""ます。"#. Tag: para#: tutorial.xml:220#, no-c-formatmsgid """This mapping file should be saved as <literal>Event.hbm.xml</literal>, right ""in the directory next to the <literal>Event</literal> Java class source ""file. The naming of mapping files can be arbitrary, however the <literal>hbm.""xml</literal> suffix is a convention in the Hibernate developer community. ""The directory structure should now look like this:"msgstr """このマッピングファイルは、<literal>Event.hbm.xml</literal> として ""<literal>Event</literal> Javaクラスソースファイルのすぐ隣にセーブするべきで""す。 マッピングファイルの命名方法は任意ですが、<literal>hbm.xml</literal> サ""フィックスがHibernateの開発者のコミュニティ内での習慣となっています。 現在""ディレクトリ構造はこのようになっているはずです:"#. Tag: programlisting#: tutorial.xml:228#, no-c-formatmsgid """<![CDATA[.\n""+lib\n""  <Hibernate and third-party libraries>\n""+src\n""  +events\n""    Event.java\n""    Event.hbm.xml]]>"msgstr ""

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -