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

📄 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 "Example: Parent/Child"#. 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 """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!"#. Tag: title#: example_parentchild.xml:21#, no-c-formatmsgid "A note about collections"msgstr "A note about collections"#. 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 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:"#. 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 """When we remove / add an object from / to a collection, the version number of ""the collection owner is incremented."#. 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 """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."#. 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 """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."#. 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 """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."#. Tag: title#: example_parentchild.xml:64#, no-c-formatmsgid "Bidirectional one-to-many"msgstr "Bidirectional one-to-many"#. 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 """Suppose we start with a simple <literal>&lt;one-to-many&gt;</literal> ""association from <literal>Parent</literal> to <literal>Child</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 "If we were to execute the following code"#. 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 would issue two SQL statements:"#. Tag: para#: example_parentchild.xml:85#, no-c-formatmsgid """an <literal>INSERT</literal> to create the record for <literal>c</literal>"msgstr """an <literal>INSERT</literal> to create the record for <literal>c</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 """an <literal>UPDATE</literal> to create the link from <literal>p</literal> to ""<literal>c</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 """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:"#. 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 "However, this is not the recommended solution."#. 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 """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."#. 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 """(We also need to add the <literal>parent</literal> property to the ""<literal>Child</literal> class.)"#. 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 """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."#. 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 "The following code would be used to add a new <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

⌨️ 快捷键说明

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