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

📄 collection_mapping.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 5 页
字号:
#. Tag: literal#: collection_mapping.xml:771#, no-c-formatmsgid "Using an &lt;idbag&gt;"msgstr "使用&lt;idbag&gt;"#. Tag: para#: collection_mapping.xml:773#, 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 """如果你完全信奉我们对于“联合主键(composite keys)是个坏东西”,和“实体应该使用""(无机的)自己生成的代用标识符(surrogate keys)”的观点,也许你会感到有一些奇""怪,我们目前为止展示的多对多关联和值集合都是映射成为带有联合主键的表的!现""在,这一点非常值得争辩;看上去一个单纯的关联表并不能从代用标识符中获得什么好""处(虽然使用组合值的集合<emphasis>可能</emphasis>会获得一点好处)。不过,""Hibernate提供了一个(一点点试验性质的)功能,让你把多对多关联和值集合应得到一""个使用代用标识符的表去。"#. Tag: para#: collection_mapping.xml:784#, 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 """<literal>&lt;idbag&gt;</literal> 属性让你使用bag语义来映射一个<literal>List</""literal> (或<literal>Collection</literal>)。"#. Tag: programlisting#: collection_mapping.xml:789#, 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:791#, 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 """你可以理解,<literal>&lt;idbag&gt;</literal>人工的id生成器,就好像是实体类一""样!集合的每一行都有一个不同的人造关键字。但是,Hibernate没有提供任何机制来让""你取得某个特定行的人造关键字。"#. Tag: para#: collection_mapping.xml:798#, 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 """注意<literal>&lt;idbag&gt;</literal>的更新性能要比普通的<literal>&lt;bag&gt;""</literal>高得多!Hibernate可以有效的定位到不同的行,分别进行更新或删除工作,""就如同处理一个list, map或者set一样。"#. Tag: para#: collection_mapping.xml:805#, 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 """在目前的实现中,还不支持使用<literal>identity</literal>标识符生成器策略来生成""<literal>&lt;idbag&gt;</literal>集合的标识符。"#. Tag: title#: collection_mapping.xml:829#, no-c-formatmsgid "Collection examples"msgstr "集合例子(Collection example)"#. Tag: para#: collection_mapping.xml:831#, no-c-formatmsgid """The previous sections are pretty confusing. So lets look at an example. This ""class:"msgstr "在前面的几个章节的确非常令人迷惑。 因此让我们来看一个例子。这个类:"#. Tag: programlisting#: collection_mapping.xml:836#, 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:838#, 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 """这个类有一个<literal>Child</literal>的实例集合。如果每一个子实例至多有一个父""实例, 那么最自然的映射是一个one-to-many的关联关系:"#. Tag: programlisting#: collection_mapping.xml:844#, 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:846#, no-c-formatmsgid "This maps to the following table definitions:"msgstr "在以下的表定义中反应了这个映射关系:"#. Tag: programlisting#: collection_mapping.xml:850#, 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:852#, no-c-formatmsgid """If the parent is <emphasis>required</emphasis>, use a bidirectional one-to-""many association:"msgstr """如果父亲是<emphasis>必须</emphasis>的, 那么就可以使用双向one-to-many的关联""了:"#. Tag: programlisting#: collection_mapping.xml:857#, 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:859#, no-c-formatmsgid "Notice the <literal>NOT NULL</literal> constraint:"msgstr "请注意<literal>NOT NULL</literal>的约束:"#. Tag: programlisting#: collection_mapping.xml:863#, 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:865#, 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 """另外,如果你绝对坚持这个关联应该是单向的,你可以对<literal>&lt;key&gt;</""literal>映射声明<literal>NOT NULL</literal>约束:"#. Tag: programlisting#: collection_mapping.xml:871#, 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:873#, no-c-formatmsgid """On the other hand, if a child might have multiple parents, a many-to-many ""association is appropriate:"msgstr """另外一方面,如果一个子实例可能有多个父实例, 那么就应该使用many-to-many关联:"#. Tag: programlisting#: collection_mapping.xml:878#, 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:880#, no-c-formatmsgid "Table definitions:"msgstr "表定义:"#. Tag: programlisting#: collection_mapping.xml:884#, 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:886#, no-c-formatmsgid """For more examples and a complete walk-through a parent/child relationship ""mapping, see <xref linkend=\"example-parentchild\"/>."msgstr """更多的例子,以及一个完整的父/子关系映射的排练,请参阅<xref linkend=\"example-""parentchild\"/>."#. Tag: para#: collection_mapping.xml:891#, no-c-formatmsgid """Even more exotic associatio

⌨️ 快捷键说明

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