alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (example_parentchild.po)

This example Hibernate source code file (example_parentchild.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.

Java - Hibernate tags/keywords

cdata, child, child, hibernate, hibernate, in, null, parent, parent, tag, tag, the, this, you

The Hibernate example_parentchild.po source code

# translation of Collection_Mapping.po to
# Xi HUANG <xhuang@redhat.com>, 2007, 2010.
msgid ""
msgstr ""
"Project-Id-Version: Collection_Mapping\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-02-10T07:25:35\n"
"PO-Revision-Date: 2010-01-20 15:29+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
#, no-c-format
msgid "Example: Parent/Child"
msgstr "例: 親/子供"

#. Tag: para
#, no-c-format
msgid ""
"One of the first things that new users want to do with Hibernate is to model "
"a parent/child type relationship. There are two different approaches to "
"this. The most convenient approach, especially for new users, is to model "
"both <literal>Parent and Child as entity "
"classes with a <literal><one-to-many> association from "
"<literal>Parent to Child. The alternative "
"approach is to declare the <literal>Child as a <"
"composite-element></literal>. The 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."
msgstr ""
"新規ユーザーが Hibernate を使ってまず最初に扱うモデルの一つに、親子型のモデル"
"化があります。このモデル化には二つのアプローチが存在します。とりわけ新規ユー"
"ザーにとって、さまざまな理由から最も便利だと思われるアプローチは、 <literal>"
"親</literal> から 子供 への <one-to-many>子供 の両方を"
"エンティティクラスとしてモデリングする方法です(もう一つの方法は、 <literal>"
"子供</literal> を <composite-element> として定義する"
"ものです)。これで( Hibernate における)一対多関連のデフォルトのセマンティク"
"スが、通常の複合要素のマッピングよりも、親子関係のセマンティクスから遠いこと"
"がわかります。それでは親子関係を効率的かつエレガントにモデリングするために、 "
"<emphasis>カスケード操作を使った双方向一対多関連 の扱い方を説明し"
"ます。これはまったく難しいものではありません。"

#. Tag: title
#, no-c-format
msgid "A note about collections"
msgstr "コレクションに関する注意"

#. Tag: para
#, no-c-format
msgid ""
"Hibernate collections are considered to be a logical part of their owning "
"entity and not of the contained entities. Be aware that this is a critical "
"distinction that has the following consequences:"
msgstr ""
"Hibernate のコレクションは自身のエンティティの論理的な部分と考えられ、決して"
"包含するエンティティのものではありません。これは致命的な違いです。これは以下"
"のような結果になります:"

#. Tag: para
#, no-c-format
msgid ""
"When you remove/add an object from/to a collection, the version number of "
"the collection owner is incremented."
msgstr ""
"オブジェクトをコレクションから削除、またはコレクションに追加するとき、コレク"
"ションのオーナーのバージョン番号はインクリメントされます。"

#. Tag: para
#, no-c-format
msgid ""
"If an object that was removed from a collection is an instance of a value "
"type (e.g. 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
#, no-c-format
msgid ""
"Conversely, 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 behavior 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
#, no-c-format
msgid ""
"Adding an entity to a collection, by default, merely creates a link between "
"the two entities. Removing the entity will remove the link. This is "
"appropriate for all sorts of cases. However, it is not appropriate in the "
"case of a parent/child relationship. In this case, the life of the child is "
"bound to the life cycle of the parent."
msgstr ""
"その代わりに、デフォルトの動作では、エンティティをコレクションに追加すると単"
"に二つのエンティティ間のリンクを作成し、一方エンティティを削除するとリンクも"
"削除します。これはすべてのケースにおいて非常に適切です。これが適切でないのは"
"親/子関係の場合です。この場合子供の生存は親のライフサイクルに制限されるからで"
"す。"

#. Tag: title
#, no-c-format
msgid "Bidirectional one-to-many"
msgstr "双方向一対多"

#. Tag: para
#, no-c-format
msgid ""
"Suppose we start with a simple <literal><one-to-many> "
"association from <literal>Parent to Child."
msgstr ""
"<literal>Parent から Child への単純な "
"<literal><one-to-many> 関連から始めるとします。"

#. Tag: para
#, no-c-format
msgid "If we were to execute the following code:"
msgstr "以下のコードを実行すると、"

#. Tag: para
#, no-c-format
msgid "Hibernate would issue two SQL statements:"
msgstr "Hibernate は二つの SQL 文を発行します:"

#. Tag: para
#, no-c-format
msgid ""
"an <literal>INSERT to create the record for c"
msgstr ""
"<literal>c に対するレコードを生成する INSERT"

#. Tag: para
#, no-c-format
msgid ""
"an <literal>UPDATE to create the link from p to "
"<literal>c"
msgstr ""
"<literal>p から c へのリンクを作成する "
"<literal>UPDATE"

#. Tag: para
#, no-c-format
msgid ""
"This is not only inefficient, but also violates any <literal>NOT NULLparent_id column. You can fix "
"the nullability constraint violation by specifying <literal>not-null=\"true"
"\"</literal> in the collection mapping:"
msgstr ""
"これは非効率的なだけではなく、 <literal>parent_id カラムにおいて "
"<literal>NOT NULL 制約に違反します。コレクションのマッピングで "
"<literal>not-null=\"true\" と指定することで、 null 制約違反を解決す"
"ることができます:"

#. Tag: para
#, no-c-format
msgid "However, this is not the recommended solution."
msgstr "しかしこの解決策は推奨できません。"

#. Tag: para
#, no-c-format
msgid ""
"The underlying cause of this behavior is that the link (the foreign key "
"<literal>parent_id) from p to cChild "
"object and is therefore not created in the <literal>INSERT. The "
"solution is to make the link part of the <literal>Child mapping."
msgstr ""
"この動作の根本的な原因は、 <literal>p から c へ"
"のリンク(外部キー <literal>parent_id) は Child "
"オブジェクトの状態の一部とは考えられず、そのため <literal>INSERT に"
"よってリンクが生成されないことです。ですから、解決策はリンクを Child マッピン"
"グの一部にすることです。"

#. Tag: para
#, no-c-format
msgid ""
"You also need to add the <literal>parent property to the "
"<literal>Child class."
msgstr ""
"(また <literal>Child クラスに parent プロパティ"
"を追加する必要があります。)"

#. Tag: para
#, no-c-format
msgid ""
"Now that the <literal>Child entity is managing the state of the "
"link, we tell the collection not to update the link. We use the "
"<literal>inverse attribute to do this:"
msgstr ""
"それでは <literal>Child エンティティがリンクの状態を制御するように"
"なったので、コレクションがリンクを更新しないようにしましょう。それには "
"<literal>inverse 属性を使います。"

#. Tag: para
#, no-c-format
msgid "The following code would be used to add a new <literal>Child:"
msgstr ""
"以下のコードを使えば、新しい <literal>Child を追加することができま"
"す。"

#. Tag: para
#, no-c-format
msgid "Only one SQL <literal>INSERT would now be issued."
msgstr ""
"これにより、 SQL の <literal>INSERT 文が一つだけが発行されるように"
"なりました。"

#. Tag: para
#, no-c-format
msgid ""
"You could also create an <literal>addChild() method of "
"<literal>Parent."
msgstr ""
"もう少し強化するには、 <literal>Parent の addChild() looks like this:"
msgstr "<literal>Child を追加するコードはこのようになります。"

#. Tag: title
#, no-c-format
msgid "Cascading life cycle"
msgstr "ライフサイクルのカスケード"

#. Tag: para
#, no-c-format
msgid ""
"You can address the frustrations of the explicit call to <literal>save() をコールするのはまだ煩わしいものです。これ"
"をカスケードを使って対処します。"

#. Tag: para
#, no-c-format
msgid "This simplifies the code above to:"
msgstr "これにより先ほどのコードをこのように単純化します"

#. Tag: para
#, no-c-format
msgid ""
"Similarly, we do not need to iterate over the children when saving or "
"deleting a <literal>Parent. The following removes p を保存または削除するときに、子供を一つ一つ取"
"り出して扱う必要はありません。以下のコードは <literal>p を削除し、"
"そしてデータベースからその子供をすべて削除します。"

#. Tag: para
#, no-c-format
msgid "However, the following code:"
msgstr "しかしこのコードは"

#. Tag: para
#, no-c-format
msgid ""
"will not remove <literal>c from the database. In this case, it "
"will only remove the link to <literal>p and cause a NOT "
"NULL</literal> constraint violation. You need to explicitly delete()"
"</literal> the Child."
msgstr ""
"データベースから <literal>c を削除しません。 p "
"へのリンクを削除する(そしてこのケースでは <literal>NOT NULL 制約違"
"反を引き起こす)だけです。 <literal>Child の delete() cannot exist without its parent. So "
"if we remove a <literal>Child from the collection, we do want it "
"to be deleted. To do this, we must use <literal>cascade=\"all-delete-orphan"
"\"</literal>."
msgstr ""
"今このケースでは実際に <literal>Child が親なしでは存在できないよう"
"になりました。そのため、もしコレクションから <literal>Child を取り"
"除く場合、これも削除します。そのためには <literal>cascade=\"all-delete-orphan"
"\"</literal> を使わなければなりません。"

#. Tag: para
#, no-c-format
msgid ""
"Even though the collection mapping specifies <literal>inverse=\"true\" と指定し"
"ても、コレクションの要素のイテレーションによって、依然カスケードが実行されま"
"す。そのため、もしカスケードでオブジェクトをセーブ、削除、更新する必要がある"
"なら、それをコレクションに追加しなければなりません。単に <literal>setParent()"
"</literal> を呼ぶだけでは不十分です。"

#. Tag: title
#, no-c-format
msgid "Cascades and <literal>unsaved-value"
msgstr "カスケードと unsaved-value"

#. Tag: para
#, fuzzy, no-c-format
msgid ""
"Suppose we loaded up a <literal>Parent in one Session. The "
"<literal>Parent will contain a collection of children and, since "
"the cascading update is enabled, Hibernate needs to know which children are "
"newly instantiated and which represent existing rows in the database. We "
"will also assume that both <literal>Parent and ChildLongIn Hibernate3, it is no longer "
"necessary to specify an <literal>unsaved-value explicitly. が、ある Session でロードされ、 "
"UI のアクションで変更が加えられ、 <literal>update() を呼んでこの変"
"更を新しいセッションで永続化したいとします。 <literal>Parent が子供"
"のコレクションを持ち、カスケード更新が有効になっているため、 Hibernate はどの"
"子供が新しくインスタンス化されたか、どれがデータベースの既存の行に相当するの"
"かを知る必要があります。 <literal>Parent と ChildLong 型の識別プロパティを生成したとしま"
"しょう。 Hibernate はどの子供が新しいものかを決定するために識別プロパティの値"
"を使います (<xref linkend=\"objectstate-saveorupdate\"/> 参照)。 "
"<emphasis>Hibernate3 になって、明示的に unsaved-value を指"
"定する必要はなくなりました。</emphasis>"

#. Tag: para
#, no-c-format
msgid ""
"The following code will update <literal>parent and childnewChild:"
msgstr ""
"以下のコードは <literal>parent と child を更新"
"し、 <literal>newChild を挿入します。"

#. Tag: para
#, no-c-format
msgid ""
"This may be suitable for the case of a generated identifier, but what about "
"assigned identifiers and composite identifiers? This is more difficult, "
"since Hibernate cannot use the identifier property to distinguish between a "
"newly instantiated object, with an identifier assigned by the user, and an "
"object loaded in a previous session. In this case, Hibernate will either use "
"the timestamp or version property, or will actually query the second-level "
"cache or, worst case, the database, to see if the row exists."
msgstr ""
"これらは生成された識別子の場合には非常に良いのですが、割り当てられた識別子と"
"複合識別子の場合はどうでしょうか?これは Hibernate が、(ユーザーにより割り当"
"てられた識別子を持つ)新しくインスタンス化されたオブジェクトと、以前の "
"Session でロードされたオブジェクトを区別できないため、より難しいです。この場"
"合、 Hibernate はタイムスタンプかバージョンのプロパティのどちらかを使うか、二"
"次キャッシュに問い合わせます。最悪の場合、行が存在するかどうかデータベースを"
"見ます。"

#. Tag: title
#, no-c-format
msgid "Conclusion"
msgstr "結論"

#. Tag: para
#, no-c-format
msgid ""
"The sections we have just covered can be a bit confusing. However, in "
"practice, it all works out nicely. Most Hibernate applications use the "
"parent/child pattern in many places."
msgstr ""
"ここではかなりの量を要約したので、最初の頃は混乱しているように思われるかもし"
"れません。しかし実際は、すべて非常に良く動作します。ほとんどの Hibernate アプ"
"リケーションでは、多くの場面で親子パターンを使用します。"

#. Tag: para
#, no-c-format
msgid ""
"We mentioned an alternative in the first paragraph. None of the above issues "
"exist in the case of <literal><composite-element> mappings, "
"which have exactly the semantics of a parent/child relationship. "
"Unfortunately, there are two big limitations with composite element classes: "
"composite elements cannot own collections and they should not be the child "
"of any entity other than the unique parent."
msgstr ""
"最初の段落で代替方法について触れました。上記のような問題は <literal><"
"composite-element></literal> マッピングの場合は存在せず、にもかかわらずそ"
"れは確かに親子関係のセマンティクスを持ちます。しかし残念ながら、複合要素クラ"
"スには2つの大きな制限があります: 1つは複合要素はコレクションを持つことがで"
"きないことです。もうひとつは、ユニークな親ではないエンティティの子供となるべ"
"きではないということです"

#, fuzzy
#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<set name=\"children\">\n"
#~ "    <key column=\"parent_id\"/>\n"
#~ "    <one-to-many class=\"Child\"/>\n"
#~ "</set>"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[Parent p = .....;\n"
#~ "Child c = new Child();\n"
#~ "p.getChildren().add(c);\n"
#~ "session.save(c);\n"
#~ "session.flush();]]>"
#~ msgstr ""
#~ "Parent p = .....;\n"
#~ "Child c = new Child();\n"
#~ "p.getChildren().add(c);\n"
#~ "session.save(c);\n"
#~ "session.flush();"

#, fuzzy
#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<set name=\"children\">\n"
#~ "    <key column=\"parent_id\" not-null=\"true\"/>\n"
#~ "    <one-to-many class=\"Child\"/>\n"
#~ "</set>"

#, fuzzy
#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<many-to-one name=\"parent\" column=\"parent_id\" not-null=\"true\"/"
#~ ">"

#, fuzzy
#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<set name=\"children\" inverse=\"true\">\n"
#~ "    <key column=\"parent_id\"/>\n"
#~ "    <one-to-many class=\"Child\"/>\n"
#~ "</set>"

#, fuzzy
#~ msgid ""
#~ "<![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 ""
#~ "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();"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[public void addChild(Child c) {\n"
#~ "    c.setParent(this);\n"
#~ "    children.add(c);\n"
#~ "}]]>"
#~ msgstr ""
#~ "public void addChild(Child c) {\n"
#~ "    c.setParent(this);\n"
#~ "    children.add(c);\n"
#~ "}"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = new Child();\n"
#~ "p.addChild(c);\n"
#~ "session.save(c);\n"
#~ "session.flush();]]>"
#~ msgstr ""
#~ "Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = new Child();\n"
#~ "p.addChild(c);\n"
#~ "session.save(c);\n"
#~ "session.flush();"

#, fuzzy
#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<set name=\"children\" inverse=\"true\" cascade=\"all\">\n"
#~ "    <key column=\"parent_id\"/>\n"
#~ "    <one-to-many class=\"Child\"/>\n"
#~ "</set>"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = new Child();\n"
#~ "p.addChild(c);\n"
#~ "session.flush();]]>"
#~ msgstr ""
#~ "Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = new Child();\n"
#~ "p.addChild(c);\n"
#~ "session.flush();"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "session.delete(p);\n"
#~ "session.flush();]]>"
#~ msgstr ""
#~ "Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "session.delete(p);\n"
#~ "session.flush();"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = (Child) p.getChildren().iterator().next();\n"
#~ "p.getChildren().remove(c);\n"
#~ "c.setParent(null);\n"
#~ "session.flush();]]>"
#~ msgstr ""
#~ "Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = (Child) p.getChildren().iterator().next();\n"
#~ "p.getChildren().remove(c);\n"
#~ "c.setParent(null);\n"
#~ "session.flush();"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = (Child) p.getChildren().iterator().next();\n"
#~ "p.getChildren().remove(c);\n"
#~ "session.delete(c);\n"
#~ "session.flush();]]>"
#~ msgstr ""
#~ "Parent p = (Parent) session.load(Parent.class, pid);\n"
#~ "Child c = (Child) p.getChildren().iterator().next();\n"
#~ "p.getChildren().remove(c);\n"
#~ "session.delete(c);\n"
#~ "session.flush();"

#, fuzzy
#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<set name=\"children\" inverse=\"true\" cascade=\"all-delete-orphan"
#~ "\">\n"
#~ "    <key column=\"parent_id\"/>\n"
#~ "    <one-to-many class=\"Child\"/>\n"
#~ "</set>"

#, fuzzy
#~ msgid ""
#~ "<![CDATA[//parent and child were both loaded in a previous session\n"
#~ "parent.addChild(child);\n"
#~ "Child newChild = new Child();\n"
#~ "parent.addChild(newChild);\n"
#~ "session.update(parent);\n"
#~ "session.flush();]]>"
#~ msgstr ""
#~ "//parent and child were both loaded in a previous session\n"
#~ "parent.addChild(child);\n"
#~ "Child newChild = new Child();\n"
#~ "parent.addChild(newChild);\n"
#~ "session.update(parent);\n"
#~ "session.flush();"

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate example_parentchild.po source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.