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

📄 collection_mapping.pot

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 POT
📖 第 1 页 / 共 4 页
字号:
msgid ""      "<![CDATA[<map name=\"connections\">\n"      "    <key column=\"incoming_node_id\"/>\n"      "    <map-key-many-to-many column=\"outgoing_node_id\" class=\"Node\"/>\n"      "    <many-to-many column=\"connection_id\" class=\"Connection\"/>\n"      "</map>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:785#, no-c-formatmsgid "A second approach is to simply remodel the association as an entity class. This is the approach we use most commonly."msgstr ""#. Tag: para#: collection_mapping.xml:790#, no-c-formatmsgid "A final alternative is to use composite elements, which we will discuss later."msgstr ""#. Tag: literal#: collection_mapping.xml:797#, no-c-formatmsgid "Using an &lt;idbag&gt;"msgstr ""#. Tag: para#: collection_mapping.xml:799#, no-c-formatmsgid "If you've fully embraced our view that composite keys are a bad thing and that entities should have synthetic identifiers (surrogate keys), then you might find it a bit odd that the many to many associations and collections of values that we've shown so far all map to tables with composite keys! Now, this point is quite arguable; a pure association table doesn't seem to benefit much from a surrogate key (though a collection of composite values <emphasis>might</emphasis>). Nevertheless, Hibernate provides a feature that allows you to map many to many associations and collections of values to a table with a surrogate key."msgstr ""#. Tag: para#: collection_mapping.xml:810#, no-c-formatmsgid "The <literal>&lt;idbag&gt;</literal> element lets you map a <literal>List</literal> (or <literal>Collection</literal>) with bag semantics."msgstr ""#. Tag: programlisting#: collection_mapping.xml:815#, no-c-formatmsgid ""      "<![CDATA[<idbag name=\"lovers\" table=\"LOVERS\">\n"      "    <collection-id column=\"ID\" type=\"long\">\n"      "        <generator class=\"sequence\"/>\n"      "    </collection-id>\n"      "    <key column=\"PERSON1\"/>\n"      "    <many-to-many column=\"PERSON2\" class=\"Person\" fetch=\"join\"/>\n"      "</idbag>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:817#, no-c-formatmsgid "As you can see, an <literal>&lt;idbag&gt;</literal> has a synthetic id generator, just like an entity class! A different surrogate key is assigned to each collection row. Hibernate does not provide any mechanism to discover the surrogate key value of a particular row, however."msgstr ""#. Tag: para#: collection_mapping.xml:824#, no-c-formatmsgid "Note that the update performance of an <literal>&lt;idbag&gt;</literal> is <emphasis>much</emphasis> better than a regular <literal>&lt;bag&gt;</literal>! Hibernate can locate individual rows efficiently and update or delete them individually, just like a list, map or set."msgstr ""#. Tag: para#: collection_mapping.xml:831#, no-c-formatmsgid "In the current implementation, the <literal>native</literal> identifier generation strategy is not supported for <literal>&lt;idbag&gt;</literal> collection identifiers."msgstr ""#. Tag: title#: collection_mapping.xml:855#, no-c-formatmsgid "Collection examples"msgstr ""#. Tag: para#: collection_mapping.xml:857#, no-c-formatmsgid "The previous sections are pretty confusing. So lets look at an example. This class:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:862#, no-c-formatmsgid ""      "<![CDATA[package eg;\n"      "import java.util.Set;\n"      "\n"      "public class Parent {\n"      "    private long id;\n"      "    private Set children;\n"      "\n"      "    public long getId() { return id; }\n"      "    private void setId(long id) { this.id=id; }\n"      "\n"      "    private Set getChildren() { return children; }\n"      "    private void setChildren(Set children) { this.children=children; }\n"      "\n"      "    ....\n"      "    ....\n"      "}]]>"msgstr ""#. Tag: para#: collection_mapping.xml:864#, no-c-formatmsgid "has a collection of <literal>Child</literal> instances. If each child has at most one parent, the most natural mapping is a one-to-many association:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:870#, no-c-formatmsgid ""      "<![CDATA[<hibernate-mapping>\n"      "\n"      "    <class name=\"Parent\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <set name=\"children\">\n"      "            <key column=\"parent_id\"/>\n"      "            <one-to-many class=\"Child\"/>\n"      "        </set>\n"      "    </class>\n"      "\n"      "    <class name=\"Child\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <property name=\"name\"/>\n"      "    </class>\n"      "\n"      "</hibernate-mapping>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:872#, no-c-formatmsgid "This maps to the following table definitions:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:876#, no-c-formatmsgid ""      "<![CDATA[create table parent ( id bigint not null primary key )\n"      "create table child ( id bigint not null primary key, name varchar(255), parent_id bigint )\n"      "alter table child add constraint childfk0 (parent_id) references parent]]>"msgstr ""#. Tag: para#: collection_mapping.xml:878#, no-c-formatmsgid "If the parent is <emphasis>required</emphasis>, use a bidirectional one-to-many association:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:883#, no-c-formatmsgid ""      "<![CDATA[<hibernate-mapping>\n"      "\n"      "    <class name=\"Parent\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <set name=\"children\" inverse=\"true\">\n"      "            <key column=\"parent_id\"/>\n"      "            <one-to-many class=\"Child\"/>\n"      "        </set>\n"      "    </class>\n"      "\n"      "    <class name=\"Child\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <property name=\"name\"/>\n"      "        <many-to-one name=\"parent\" class=\"Parent\" column=\"parent_id\" not-null=\"true\"/>\n"      "    </class>\n"      "\n"      "</hibernate-mapping>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:885#, no-c-formatmsgid "Notice the <literal>NOT NULL</literal> constraint:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:889#, no-c-formatmsgid ""      "<![CDATA[create table parent ( id bigint not null primary key )\n"      "create table child ( id bigint not null\n"      "                     primary key,\n"      "                     name varchar(255),\n"      "                     parent_id bigint not null )\n"      "alter table child add constraint childfk0 (parent_id) references parent]]>"msgstr ""#. Tag: para#: collection_mapping.xml:891#, no-c-formatmsgid "Alternatively, if you absolutely insist that this association should be unidirectional, you can declare the <literal>NOT NULL</literal> constraint on the <literal>&lt;key&gt;</literal> mapping:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:897#, no-c-formatmsgid ""      "<![CDATA[<hibernate-mapping>\n"      "\n"      "    <class name=\"Parent\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <set name=\"children\">\n"      "            <key column=\"parent_id\" not-null=\"true\"/>\n"      "            <one-to-many class=\"Child\"/>\n"      "        </set>\n"      "    </class>\n"      "\n"      "    <class name=\"Child\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <property name=\"name\"/>\n"      "    </class>\n"      "\n"      "</hibernate-mapping>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:899#, no-c-formatmsgid "On the other hand, if a child might have multiple parents, a many-to-many association is appropriate:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:904#, no-c-formatmsgid ""      "<![CDATA[<hibernate-mapping>\n"      "\n"      "    <class name=\"Parent\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <set name=\"children\" table=\"childset\">\n"      "            <key column=\"parent_id\"/>\n"      "            <many-to-many class=\"Child\" column=\"child_id\"/>\n"      "        </set>\n"      "    </class>\n"      "\n"      "    <class name=\"Child\">\n"      "        <id name=\"id\">\n"      "            <generator class=\"sequence\"/>\n"      "        </id>\n"      "        <property name=\"name\"/>\n"      "    </class>\n"      "\n"      "</hibernate-mapping>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:906#, no-c-formatmsgid "Table definitions:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:910#, no-c-formatmsgid ""      "<![CDATA[create table parent ( id bigint not null primary key )\n"      "create table child ( id bigint not null primary key, name varchar(255) )\n"      "create table childset ( parent_id bigint not null,\n"      "                        child_id bigint not null,\n"      "                        primary key ( parent_id, child_id ) )\n"      "alter table childset add constraint childsetfk0 (parent_id) references parent\n"      "alter table childset add constraint childsetfk1 (child_id) references child]]>"msgstr ""#. Tag: para#: collection_mapping.xml:912#, no-c-formatmsgid "For more examples and a complete walk-through a parent/child relationship mapping, see <xref linkend=\"example-parentchild\"/>."msgstr ""#. Tag: para#: collection_mapping.xml:917#, no-c-formatmsgid "Even more exotic association mappings are possible, we will catalog all possibilities in the next chapter."msgstr ""

⌨️ 快捷键说明

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