📄 example_parentchild.po
字号:
#, no-c-formatmsgid "And now, only one SQL <literal>INSERT</literal> would be issued!"msgstr "Maintenant, seul un <literal>INSERT</literal> SQL est nécessaire !"#. Tag: para#: example_parentchild.xml:160#, no-c-formatmsgid """To tighten things up a bit, we could create an <literal>addChild()</literal> ""method of <literal>Parent</literal>."msgstr """Pour alléger encore un peu les choses, nous devrions créer une méthode ""<literal>addChild()</literal> dans <literal>Parent</literal>."#. Tag: programlisting#: example_parentchild.xml:165#, no-c-formatmsgid """<![CDATA[public void addChild(Child c) {\n"" c.setParent(this);\n"" children.add(c);\n""}]]>"msgstr ""#. Tag: para#: example_parentchild.xml:167#, no-c-formatmsgid "Now, the code to add a <literal>Child</literal> looks like"msgstr "Le code d'ajout d'un <literal>Child</literal> serait alors"#. Tag: programlisting#: example_parentchild.xml:171#, 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:176#, no-c-formatmsgid "Cascading life cycle"msgstr "Cycle de vie en cascade"#. Tag: para#: example_parentchild.xml:178#, no-c-formatmsgid """The explicit call to <literal>save()</literal> is still annoying. We will ""address this by using cascades."msgstr """L'appel explicite de <literal>save()</literal> est un peu fastidieux. Nous ""pouvons simplifier cela en utilisant les cascades."#. Tag: programlisting#: example_parentchild.xml:183#, 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:185#, no-c-formatmsgid "This simplifies the code above to"msgstr "Simplifie le code précédent en"#. Tag: programlisting#: example_parentchild.xml:189#, 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:191#, 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 """De la même manière, nous n'avons pas à itérer sur les fils lorsque nous ""sauvons ou effacons un <literal>Parent</literal>. Le code suivant efface ""<literal>p</literal> et tous ses fils de la base de données."#. Tag: programlisting#: example_parentchild.xml:196#, 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:198#, no-c-formatmsgid "However, this code"msgstr "Par contre, ce code"#. Tag: programlisting#: example_parentchild.xml:202#, 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:204#, 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 """n'effacera pas <literal>c</literal> de la base de données, il enlèvera ""seulement le lien vers <literal>p</literal> (et causera une violation de ""contrainte <literal>NOT NULL</literal>, dans ce cas). Vous devez ""explicitement utiliser <literal>delete()</literal> sur <literal>Child</""literal>."#. Tag: programlisting#: example_parentchild.xml:210#, 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:212#, 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 """Dans notre cas, un <literal>Child</literal> ne peut pas vraiment exister ""sans son père. Si nous effacons un <literal>Child</literal> de la ""collection, nous voulons vraiment qu'il soit effacé. Pour cela, nous devons ""utiliser <literal>cascade=\"all-delete-orphan\"</literal>."#. Tag: programlisting#: example_parentchild.xml:218#, 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:220#, 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 """A noter : même si le mapping de la collection spécifie <literal>inverse=""\"true\"</literal>, les cascades sont toujours assurées par l'itération sur ""les éléments de la collection. Donc, si vous avez besoin qu'un objet soit ""enregistré, effacé ou mis à jour par cascade, vous devez l'ajouter dans la ""colleciton. Il ne suffit pas d'appeler explicitement <literal>setParent()</""literal>."#. Tag: title#: example_parentchild.xml:230#, no-c-formatmsgid "Cascades and <literal>unsaved-value</literal>"msgstr "Cascades et <literal>unsaved-value</literal>"#. Tag: para#: example_parentchild.xml:232#, 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 """Supposons que nous ayons chargé un <literal>Parent</literal> dans une ""<literal>Session</literal>, que nous l'ayons ensuite modifié et que voulions ""persiter ces modifications dans une nouvelle session en appelant ""<literal>update()</literal>. Le <literal>Parent</literal> contiendra une ""collection de fils et, puisque la cascade est activée, Hibernate a besoin de ""savoir quels fils viennent d'être instanciés et quels fils proviennent de la ""base de données. Supposons aussi que <literal>Parent</literal> et ""<literal>Child</literal> ont tous deux des identifiants du type ""<literal>Long</literal>. Hibernate utilisera la propriété de l'identifiant ""et la propriété de la version/horodatage pour déterminer quels fils sont ""nouveaux (vous pouvez aussi utiliser la propriété version ou timestamp, voir ""<xref linkend=\"manipulatingdata-updating-detached\"/>). <emphasis>Dans ""Hibernate3, il n'est plus nécessaire de spécifier une <literal>unsaved-""value</literal> explicitement.</emphasis>"#. Tag: para#: example_parentchild.xml:244#, no-c-formatmsgid """The following code will update <literal>parent</literal> and <literal>child</""literal> and insert <literal>newChild</literal>."msgstr """Le code suivant mettra à jour <literal>parent</literal> et <literal>child</""literal> et insérera <literal>newChild</literal>."#. Tag: programlisting#: example_parentchild.xml:249#, 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:251#, 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 """Ceci est très bien pour des identifiants générés, mais qu'en est-il des ""identifiants assignés et des identifiants composés ? C'est plus difficile, ""puisqu'Hibernate ne peut pas utiliser la propriété de l'identifiant pour ""distinguer un objet nouvellement instancié (avec un identifiant assigné par ""l'utilisateur) d'un objet chargé dans une session précédente. Dans ce cas, ""Hibernate utilisera soit la propriété de version ou d'horodatage, soit ""effectuera vraiment une requête au cache de second niveau, soit, dans le ""pire des cas, à la base de données, pour voir si la ligne existe."#. Tag: title#: example_parentchild.xml:284#, no-c-formatmsgid "Conclusion"msgstr "Conclusion"#. Tag: para#: example_parentchild.xml:286#, 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 """Il y a quelques principes à maîtriser dans ce chapitre et tout cela peut ""paraître déroutant la première fois. Cependant, dans la pratique, tout ""fonctionne parfaitement. La plupart des applications Hibernate utilisent le ""pattern père / fils."#. Tag: para#: example_parentchild.xml:291#, no-c-formatmsgid """We mentioned an alternative in the first paragraph. None of the above issues ""exist in the case of <literal><composite-element></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 """Nous avons évoqué une alternative dans le premier paragraphe. Aucun des ""points traités précédemment n'existe dans le cas d'un mapping <literal><""composite-element></literal> qui possède exactement la sémantique d'une ""relation père / fils. Malheureusement, il y a deux grandes limitations pour ""les classes éléments composites : les éléments composites ne peuvent ""contenir de collections, et ils ne peuvent être les fils d'entités autres ""que l'unique parent."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -