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

📄 example_parentchild.po

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 PO
📖 第 1 页 / 共 2 页
字号:
msgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: http://bugs.kde.org\n""POT-Creation-Date: 2008-08-14 15:28+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:29#, no-c-formatmsgid "Example: Parent/Child"msgstr "Exemple : Père/Fils"#. Tag: para#: example_parentchild.xml:31#, 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 """L'une des premières choses que les nouveaux utilisateurs essaient de faire ""avec Hibernate est de modéliser une relation père/fils. Il y a deux ""approches différentes pour cela. Pour un certain nombre de raisons, la ""méthode la plus courante, en particulier pour les nouveaux utilisateurs, est ""de modéliser les deux relations <literal>Père</literal> et <literal>Fils</""literal> comme des classes entités liées par une association <literal>&lt;""one-to-many&gt;</literal> du <literal>Père</literal> vers le <literal>Fils</""literal> (l'autre approche est de déclarer le <literal>Fils</literal> comme ""un <literal>&lt;composite-element&gt;</literal>). Il est évident que le sens ""de l'association un vers plusieurs (dans Hibernate) est bien moins proche du ""sens habituel d'une relation père/fils que ne l'est celui d'un élément ""cmposite. Nous allons vous expliquer comment utiliser une association ""<emphasis>un vers plusieurs bidirectionnelle avec cascade</emphasis> afin de ""modéliser efficacement et élégamment une relation père/fils, ce n'est ""vraiment pas difficile !"#. Tag: title#: example_parentchild.xml:45#, no-c-formatmsgid "A note about collections"msgstr "Une note à propos des collections"#. Tag: para#: example_parentchild.xml:47#, 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 """Les collections Hibernate sont considérées comme étant une partie logique de ""l'entité dans laquelle elles sont contenues ; jamais des entités qu'elle ""contient. C'est une distinction crutiale ! Les conséquences sont les ""suivantes :"#. Tag: para#: example_parentchild.xml:54#, no-c-formatmsgid """When we remove / add an object from / to a collection, the version number of ""the collection owner is incremented."msgstr """Quand nous ajoutons / retirons un objet d'une collection, le numéro de ""version du propriétaire de la collection est incrémenté."#. Tag: para#: example_parentchild.xml:60#, 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 """Si un objet qui a été enlevé d'une collection est une instance de type ""valeur (ex : élément composite), cet objet cessera d'être persistant et son ""état sera complètement effacé de la base de données. Par ailleurs, ajouter ""une instance de type valeur dans une collection aura pour conséquence que ""son état sera immédiatement persistant."#. Tag: para#: example_parentchild.xml:68#, 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 """Si une entité est enlevée d'une collection (association un-vers-plusieurs ou ""plusieurs-vers-plusieurs), par défaut, elle ne sera pas effacée. Ce ""comportement est complètement logique - une modification de l'un des états ""internes d'une entité ne doit pas causer la disparition de l'entité ""associée ! De même, l'ajout d'une entité dans une collection n'engendre pas, ""par défaut, la persistance de cette entité."#. Tag: para#: example_parentchild.xml:78#, 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 """Le comportement par défaut est donc que l'ajout d'une entité dans une ""collection créé simplement le lien entre les deux entités, et qu'effacer une ""entité supprime ce lien. C'est le comportement le plus approprié dans la ""plupart des cas. Ce comportement n'est cependant pas approprié lorsque la ""vie du fils est liée au cycle de vie du père."#. Tag: title#: example_parentchild.xml:88#, no-c-formatmsgid "Bidirectional one-to-many"msgstr "un-vers-plusieurs bidirectionnel"#. Tag: para#: example_parentchild.xml:90#, 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 """Supposons que nous ayons une simple association <literal>&lt;one-to-many&gt;""</literal> de <literal>Parent</literal> vers <literal>Child</literal>."#. Tag: programlisting#: example_parentchild.xml:95#, 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:97#, no-c-formatmsgid "If we were to execute the following code"msgstr "Si nous executions le code suivant"#. Tag: programlisting#: example_parentchild.xml:101#, 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:103#, no-c-formatmsgid "Hibernate would issue two SQL statements:"msgstr "Hibernate exécuterait deux ordres SQL:"#. Tag: para#: example_parentchild.xml:109#, no-c-formatmsgid """an <literal>INSERT</literal> to create the record for <literal>c</literal>"msgstr """un <literal>INSERT</literal> pour créer l'enregistrement pour <literal>c</""literal>"#. Tag: para#: example_parentchild.xml:112#, no-c-formatmsgid """an <literal>UPDATE</literal> to create the link from <literal>p</literal> to ""<literal>c</literal>"msgstr """un <literal>UPDATE</literal> pour créer le lien de <literal>p</literal> vers ""<literal>c</literal>"#. Tag: para#: example_parentchild.xml:119#, 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 """Ceci est non seuleument inefficace, mais viole aussi toute contrainte ""<literal>NOT NULL</literal> sur la colonne <literal>parent_id</literal>. ""Nous pouvons réparer la contrainte de nullité en spécifiant <literal>not-""null=\"true\"</literal> dans le mapping de la collection :"#. Tag: programlisting#: example_parentchild.xml:125#, 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:127#, no-c-formatmsgid "However, this is not the recommended solution."msgstr "Cependant ce n'est pas la solution recommandée."#. Tag: para#: example_parentchild.xml:130#, 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 """La cause sous jacente à ce comportement est que le lien (la clé étrangère ""<literal>parent_id</literal>) de <literal>p</literal> vers <literal>c</""literal> n'est pas considérée comme faisant partie de l'état de l'objet ""<literal>Child</literal> et n'est donc pas créé par l'<literal>INSERT</""literal>. La solution est donc que ce lien fasse partie du mapping de ""<literal>Child</literal>."#. Tag: programlisting#: example_parentchild.xml:137#, no-c-formatmsgid """<![CDATA[<many-to-one name=\"parent\" column=\"parent_id\" not-null=\"true\"/"">]]>"msgstr ""#. Tag: para#: example_parentchild.xml:139#, no-c-formatmsgid """(We also need to add the <literal>parent</literal> property to the ""<literal>Child</literal> class.)"msgstr """(Nous avons aussi besoin d'ajouter la propriété <literal>parent</literal> ""dans la classe <literal>Child</literal>)."#. Tag: para#: example_parentchild.xml:143#, 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 """Maintenant que l'état du lien est géré par l'entité <literal>Child</""literal>, nous spécifions à la collection de ne pas mettre à jour le lien. ""Nous utilisons l'attribut <literal>inverse</literal>."#. Tag: programlisting#: example_parentchild.xml:148#, 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:150#, no-c-formatmsgid "The following code would be used to add a new <literal>Child</literal>"msgstr """Le code suivant serait utilisé pour ajouter un nouveau <literal>Child</""literal>"#. Tag: programlisting#: example_parentchild.xml:154#, 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:156

⌨️ 快捷键说明

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