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

📄 example_parentchild.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 2 页
字号:
msgid "And now, only one SQL <literal>INSERT</literal> would be issued!"msgstr """これにより、SQLの <literal>INSERT</literal> 文が一つだけが発行されるようにな""りました!"#. Tag: para#: example_parentchild.xml:136#, no-c-formatmsgid """To tighten things up a bit, we could create an <literal>addChild()</literal> ""method of <literal>Parent</literal>."msgstr """もう少し強化するには、<literal>Parent</literal> の <literal>addChild()</""literal> メソッドを作成します。"#. Tag: programlisting#: example_parentchild.xml:141#, no-c-formatmsgid """<![CDATA[public void addChild(Child c) {\n""    c.setParent(this);\n""    children.add(c);\n""}]]>"msgstr ""#. Tag: para#: example_parentchild.xml:143#, no-c-formatmsgid "Now, the code to add a <literal>Child</literal> looks like"msgstr "<literal>Child</literal> を追加するコードはこのようになります。"#. Tag: programlisting#: example_parentchild.xml:147#, no-c-formatmsgid """<![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 ""#. Tag: title#: example_parentchild.xml:152#, no-c-formatmsgid "Cascading life cycle"msgstr "ライフサイクルのカスケード"#. Tag: para#: example_parentchild.xml:154#, no-c-formatmsgid """The explicit call to <literal>save()</literal> is still annoying. We will ""address this by using cascades."msgstr """明示的に <literal>save()</literal> をコールするのはまだ煩わしいものです。これ""をカスケードを使って対処します。"#. Tag: programlisting#: example_parentchild.xml:159#, no-c-formatmsgid """<![CDATA[<set name=\"children\" inverse=\"true\" cascade=\"all\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr ""#. Tag: para#: example_parentchild.xml:161#, no-c-formatmsgid "This simplifies the code above to"msgstr "これにより先ほどのコードをこのように単純化します"#. Tag: programlisting#: example_parentchild.xml:165#, no-c-formatmsgid """<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n""Child c = new Child();\n""p.addChild(c);\n""session.flush();]]>"msgstr ""#. Tag: para#: example_parentchild.xml:167#, no-c-formatmsgid """Similarly, we don't need to iterate over the children when saving or ""deleting a <literal>Parent</literal>. The following removes <literal>p</""literal> and all its children from the database."msgstr """同様に <literal>Parent</literal> を保存または削除するときに、子供を一つ一つ取""り出して扱う必要はありません。 以下のコードは <literal>p</literal> を削除し、""そしてデータベースからその子供をすべて削除します。"#. Tag: programlisting#: example_parentchild.xml:172#, no-c-formatmsgid """<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n""session.delete(p);\n""session.flush();]]>"msgstr ""#. Tag: para#: example_parentchild.xml:174#, no-c-formatmsgid "However, this code"msgstr "しかしこのコードは"#. Tag: programlisting#: example_parentchild.xml:178#, no-c-formatmsgid """<![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 ""#. Tag: para#: example_parentchild.xml:180#, no-c-formatmsgid """will not remove <literal>c</literal> from the database; it will ony remove ""the link to <literal>p</literal> (and cause a <literal>NOT NULL</literal> ""constraint violation, in this case). You need to explicitly <literal>delete()""</literal> the <literal>Child</literal>."msgstr """データベースから <literal>c</literal> を削除しません。<literal>p</literal> へ""のリンクを削除する (そしてこのケースでは <literal>NOT NULL</literal> 制約違""反を引き起こす)だけです。 <literal>Child</literal> の <literal>delete()</""literal> を明示する必要があります。"#. Tag: programlisting#: example_parentchild.xml:186#, no-c-formatmsgid """<![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 ""#. Tag: para#: example_parentchild.xml:188#, no-c-formatmsgid """Now, in our case, a <literal>Child</literal> can't really exist without its ""parent. So if we remove a <literal>Child</literal> from the collection, we ""really do want it to be deleted. For this, we must use <literal>cascade=""\"all-delete-orphan\"</literal>."msgstr """今このケースでは実際に <literal>Child</literal> が親なしでは存在できないよう""になりました。 そのため、もしコレクションから <literal>Child</literal> を取り""除く場合、これも削除したいです。 そのためには <literal>cascade=\"all-delete-""orphan\"</literal> を使わなければなりません。"#. Tag: programlisting#: example_parentchild.xml:194#, no-c-formatmsgid """<![CDATA[<set name=\"children\" inverse=\"true\" cascade=\"all-delete-orphan""\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr ""#. Tag: para#: example_parentchild.xml:196#, no-c-formatmsgid """Note: even though the collection mapping specifies <literal>inverse=\"true""\"</literal>, cascades are still processed by iterating the collection ""elements. So if you require that an object be saved, deleted or updated by ""cascade, you must add it to the collection. It is not enough to simply call ""<literal>setParent()</literal>."msgstr """注意:コレクションのマッピングで <literal>inverse=\"true\"</literal> と指定し""ても、 コレクションの要素のイテレーションによって、依然カスケードが実行されま""す。 そのためもしカスケードでオブジェクトをセーブ、削除、更新する必要があるな""ら、 それをコレクションに追加しなければなりません。単に <literal>setParent()""</literal> を呼ぶだけでは不十分です。"#. Tag: title#: example_parentchild.xml:206#, no-c-formatmsgid "Cascades and <literal>unsaved-value</literal>"msgstr "カスケードと <literal>unsaved-value</literal>"#. Tag: para#: example_parentchild.xml:208#, no-c-formatmsgid """Suppose we loaded up a <literal>Parent</literal> in one <literal>Session</""literal>, made some changes in a UI action and wish to persist these changes ""in a new session by calling <literal>update()</literal>. The ""<literal>Parent</literal> will contain a collection of childen and, since ""cascading update is enabled, Hibernate needs to know which children are ""newly instantiated and which represent existing rows in the database. Lets ""assume that both <literal>Parent</literal> and <literal>Child</literal> have ""genenerated identifier properties of type <literal>Long</literal>. Hibernate ""will use the identifier and version/timestamp property value to determine ""which of the children are new. (See <xref linkend=\"objectstate-saveorupdate""\"/>.) <emphasis>In Hibernate3, it is no longer necessary to specify an ""<literal>unsaved-value</literal> explicitly.</emphasis>"msgstr """<literal>Parent</literal> が、ある <literal>Session</literal> でロードされ、""UIのアクションで変更が加えられ、 <literal>update()</literal> を呼んでこの変更""を新しいセッションで永続化したいとします。 <literal>Parent</literal> が子供の""コレクションを持ち、カスケード更新が有効になっているため、 Hibernateはどの子""供が新しくインスタンス化されたか、どれがデータベースの既存の行に相当するのか""を知る必要があります。 <literal>Parent</literal> と <literal>Child</literal> ""の両方が <literal>java.lang.Long</literal> 型の識別プロパティを生成したとしま""しょう。 Hibernateはどの子供が新しいものかを決定するために識別プロパティの値""を使います(versionやtimestampプロパティも使えます。 <xref linkend=""\"manipulatingdata-updating-detached\"/> 参照)。Hibernate3になって、 明示的""に <literal>unsaved-value</literal> を指定する必要はなくなりました。"#. Tag: para#: example_parentchild.xml:220#, no-c-formatmsgid """The following code will update <literal>parent</literal> and <literal>child</""literal> and insert <literal>newChild</literal>."msgstr """以下のコードは <literal>parent</literal> と <literal>child</literal> を更新""し、<literal>newChild</literal> を挿入します。"#. Tag: programlisting#: example_parentchild.xml:225#, no-c-formatmsgid """<![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 ""#. Tag: para#: example_parentchild.xml:227#, no-c-formatmsgid """Well, that's all very well for the case of a generated identifier, but what ""about assigned identifiers and composite identifiers? This is more ""difficult, since Hibernate can't 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#: example_parentchild.xml:260#, no-c-formatmsgid "Conclusion"msgstr "結論"#. Tag: para#: example_parentchild.xml:262#, no-c-formatmsgid """There is quite a bit to digest here and it might look confusing first time ""around. However, in practice, it all works out very nicely. Most Hibernate ""applications use the parent / child pattern in many places."msgstr """ここではかなりの量を要約したので、最初の頃は混乱しているように思われるかもし""れません。 しかし実際は、すべて非常に良く動作します。ほとんどのHibernateアプ""リケーションでは、多くの場面で親子パターンを使用します。"#. Tag: para#: example_parentchild.xml:267#, no-c-formatmsgid """We mentioned an alternative in the first paragraph. None of the above issues ""exist in the case of <literal>&lt;composite-element&gt;</literal> mappings, ""which have exactly the semantics of a parent / child relationship. ""Unfortunately, there are two big limitations to composite element classes: ""composite elements may not own collections, and they should not be the child ""of any entity other than the unique parent."msgstr """最初の段落で代替方法について触れました。上記のような問題は <literal>&lt;""composite-element&gt;</literal> マッピングの場合は存在せず、 にもかかわらずそ""れは確かに親子関係のセマンティクスを持ちます。 しかし残念ながら、複合要素クラ""スには二つの大きな制限があります: 1つは複合要素はコレクションを持つことがで""きないことです。もうひとつは、 ユニークな親ではないエンティティの子供となるべ""きではないということです"

⌨️ 快捷键说明

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