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

📄 example_parentchild.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 2 页
字号:
msgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: http://bugs.kde.org\n""POT-Creation-Date: 2007-10-25 07:47+0000\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <LL@li.org>\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"#. Tag: title#: example_parentchild.xml:5#, no-c-formatmsgid "Example: Parent/Child"msgstr "例:親/子供"#. Tag: para#: example_parentchild.xml:7#, no-c-formatmsgid """One of the very first things that new users try to do with Hibernate is to ""model a parent / child type relationship. There are two different approaches ""to this. For various reasons the most convenient approach, especially for ""new users, is to model both <literal>Parent</literal> and <literal>Child</""literal> as entity classes with a <literal>&lt;one-to-many&gt;</literal> ""association from <literal>Parent</literal> to <literal>Child</literal>. (The ""alternative approach is to declare the <literal>Child</literal> as a ""<literal>&lt;composite-element&gt;</literal>.) Now, it turns out that ""default semantics of a one to many association (in Hibernate) are much less ""close to the usual semantics of a parent / child relationship than those of ""a composite element mapping. We will explain how to use a ""<emphasis>bidirectional one to many association with cascades</emphasis> to ""model a parent / child relationship efficiently and elegantly. It's not at ""all difficult!"msgstr """新規ユーザがHibernateを使ってまず最初に扱うモデルの一つに、親子型のモデル化が""あります。 このモデル化には二つのアプローチが存在します。とりわけ新規ユーザに""とって、 さまざまな理由から最も便利だと思われるアプローチは、<literal>親</""literal> から <literal>子供</literal> への <literal>&lt;one-to-many&gt;</""literal> 関連により <literal>親</literal> と <literal>子供</literal> の両方を""エンティティクラスとしてモデリングする方法です (もう一つの方法は、<literal>""子供</literal> を <literal>&lt;composite-element&gt;</literal> として定義する""ものです)。 これで(Hibernateにおける)一対多関連のデフォルトのセマンティク""スが、通常の複合要素のマッピングよりも、 親子関係のセマンティクスから遠いこと""がわかります。 それでは親子関係を効率的かつエレガントにモデリングするため""に、 <emphasis>カスケード操作を使った双方向一対多関連</emphasis> の扱い方を説""明します。これはまったく難しいものではありません。"#. Tag: title#: example_parentchild.xml:21#, no-c-formatmsgid "A note about collections"msgstr "コレクションに関する注意"#. Tag: para#: example_parentchild.xml:23#, no-c-formatmsgid """Hibernate collections are considered to be a logical part of their owning ""entity; never of the contained entities. This is a crucial distinction! It ""has the following consequences:"msgstr """Hibernateのコレクションは自身のエンティティの論理的な部分と考えられ、 決して""包含するエンティティのものではありません。これは致命的な違いです! これは以下""のような結果になります:"#. Tag: para#: example_parentchild.xml:30#, no-c-formatmsgid """When we remove / add an object from / to a collection, the version number of ""the collection owner is incremented."msgstr """オブジェクトをコレクションから削除、またはコレクションに追加するとき、 コレク""ションのオーナーのバージョン番号はインクリメントされます。"#. Tag: para#: example_parentchild.xml:36#, no-c-formatmsgid """If an object that was removed from a collection is an instance of a value ""type (eg, a composite element), that object will cease to be persistent and ""its state will be completely removed from the database. Likewise, adding a ""value type instance to the collection will cause its state to be immediately ""persistent."msgstr """もしコレクションから削除されたオブジェクトが値型のインスタンス (例えばコンポ""ジットエレメント)だったならば、そのオブジェクトは永続的ではなくなり、 その状""態はデータベースから完全に削除されます。 同じように、値型のインスタンスをコレ""クションに追加すると、その状態はすぐに永続的になります。"#. Tag: para#: example_parentchild.xml:44#, no-c-formatmsgid """On the other hand, if an entity is removed from a collection (a one-to-many ""or many-to-many association), it will not be deleted, by default. This ""behaviour is completely consistent - a change to the internal state of ""another entity should not cause the associated entity to vanish! Likewise, ""adding an entity to a collection does not cause that entity to become ""persistent, by default."msgstr """一方、もしエンティティがコレクション(一対多または多対多関連)から削除されて""も、 デフォルトではそれは削除されません。この動作は完全に一貫しています。 す""なわち、他のエンティティの内部状態を変更しても、関連するエンティティが消滅す""べきではないということです。 同様に、エンティティがコレクションに追加されて""も、デフォルトではそのエンティティは永続的にはなりません。"#. Tag: para#: example_parentchild.xml:54#, no-c-formatmsgid """Instead, the default behaviour is that adding an entity to a collection ""merely creates a link between the two entities, while removing it removes ""the link. This is very appropriate for all sorts of cases. Where it is not ""appropriate at all is the case of a parent / child relationship, where the ""life of the child is bound to the life cycle of the parent."msgstr """その代わりに、デフォルトの動作では、エンティティをコレクションに追加すると単""に二つのエンティティ間のリンクを作成し、 一方エンティティを削除するとリンクも""削除します。これはすべてのケースにおいて非常に適切です。 これが適切でないのは""親/子関係の場合です。この場合子供の生存は親のライフサイクルに制限されるからで""す。"#. Tag: title#: example_parentchild.xml:64#, no-c-formatmsgid "Bidirectional one-to-many"msgstr "双方向一対多"#. Tag: para#: example_parentchild.xml:66#, no-c-formatmsgid """Suppose we start with a simple <literal>&lt;one-to-many&gt;</literal> ""association from <literal>Parent</literal> to <literal>Child</literal>."msgstr """<literal>Parent</literal> から <literal>Child</literal> への単純な ""<literal>&lt;one-to-many&gt;</literal> 関連から始めるとします。"#. Tag: programlisting#: example_parentchild.xml:71#, no-c-formatmsgid """<![CDATA[<set name=\"children\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr ""#. Tag: para#: example_parentchild.xml:73#, no-c-formatmsgid "If we were to execute the following code"msgstr "以下のコードを実行すると、"#. Tag: programlisting#: example_parentchild.xml:77#, no-c-formatmsgid """<![CDATA[Parent p = .....;\n""Child c = new Child();\n""p.getChildren().add(c);\n""session.save(c);\n""session.flush();]]>"msgstr ""#. Tag: para#: example_parentchild.xml:79#, no-c-formatmsgid "Hibernate would issue two SQL statements:"msgstr "Hibernateは二つのSQL文を発行します:"#. Tag: para#: example_parentchild.xml:85#, no-c-formatmsgid """an <literal>INSERT</literal> to create the record for <literal>c</literal>"msgstr """<literal>c</literal>に対するレコードを生成する<literal>INSERT</literal>"#. Tag: para#: example_parentchild.xml:88#, no-c-formatmsgid """an <literal>UPDATE</literal> to create the link from <literal>p</literal> to ""<literal>c</literal>"msgstr """<literal>p</literal>から<literal>c</literal>へのリンクを作成する""<literal>UPDATE</literal>"#. Tag: para#: example_parentchild.xml:95#, no-c-formatmsgid """This is not only inefficient, but also violates any <literal>NOT NULL</""literal> constraint on the <literal>parent_id</literal> column. We can fix ""the nullability constraint violation by specifying <literal>not-null=\"true""\"</literal> in the collection mapping:"msgstr """これは非効率的なだけではなく、<literal>parent_id</literal> カラムにおいて ""<literal>NOT NULL</literal> 制約に違反します。 コレクションのマッピングで ""<literal>not-null=\"true\"</literal> と指定することで、null制約違反を解決する""ことができます:"#. Tag: programlisting#: example_parentchild.xml:101#, no-c-formatmsgid """<![CDATA[<set name=\"children\">\n""    <key column=\"parent_id\" not-null=\"true\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr ""#. Tag: para#: example_parentchild.xml:103#, no-c-formatmsgid "However, this is not the recommended solution."msgstr "しかしこの解決策は推奨できません。"#. Tag: para#: example_parentchild.xml:106#, no-c-formatmsgid """The underlying cause of this behaviour is that the link (the foreign key ""<literal>parent_id</literal>) from <literal>p</literal> to <literal>c</""literal> is not considered part of the state of the <literal>Child</literal> ""object and is therefore not created in the <literal>INSERT</literal>. So the ""solution is to make the link part of the <literal>Child</literal> mapping."msgstr """この動作の根本的な原因は、<literal>p</literal> から <literal>c</literal> への""リンク (外部キー <literal>parent_id</literal>)は <literal>Child</literal> オ""ブジェクトの状態の一部とは考えられず、 そのため <literal>INSERT</literal> に""よってリンクが生成されないことです。 ですから、解決策はリンクをChildマッピン""グの一部にすることです。"#. Tag: programlisting#: example_parentchild.xml:113#, no-c-formatmsgid """<![CDATA[<many-to-one name=\"parent\" column=\"parent_id\" not-null=\"true\"/"">]]>"msgstr ""#. Tag: para#: example_parentchild.xml:115#, no-c-formatmsgid """(We also need to add the <literal>parent</literal> property to the ""<literal>Child</literal> class.)"msgstr """(また <literal>Child</literal> クラスに <literal>parent</literal> プロパティ""を追加する必要があります。)"#. Tag: para#: example_parentchild.xml:119#, no-c-formatmsgid """Now that the <literal>Child</literal> entity is managing the state of the ""link, we tell the collection not to update the link. We use the ""<literal>inverse</literal> attribute."msgstr """それでは <literal>Child</literal> エンティティがリンクの状態を制御するように""なったので、 コレクションがリンクを更新しないようにしましょう。それには ""<literal>inverse</literal> 属性を使います。"#. Tag: programlisting#: example_parentchild.xml:124#, no-c-formatmsgid """<![CDATA[<set name=\"children\" inverse=\"true\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr ""#. Tag: para#: example_parentchild.xml:126#, no-c-formatmsgid "The following code would be used to add a new <literal>Child</literal>"msgstr """以下のコードを使えば、新しい <literal>Child</literal> を追加することができま""す。"#. Tag: programlisting#: example_parentchild.xml:130#, no-c-formatmsgid """<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n""Child c = new Child();\n""c.setParent(p);\n""p.getChildren().add(c);\n""session.save(c);\n""session.flush();]]>"msgstr ""#. Tag: para#: example_parentchild.xml:132#, no-c-format

⌨️ 快捷键说明

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