📄 collection_mapping.po
字号:
#. Tag: para#: collection_mapping.xml:639#, no-c-formatmsgid """Associations may even be sorted by some arbitrary criteria at runtime using ""a collection <literal>filter()</literal>."msgstr """关联还可以在运行时使用集合<literal>filter()</literal>根据任意的条件来排序。"#. Tag: programlisting#: collection_mapping.xml:644#, no-c-formatmsgid """<![CDATA[sortedUsers = s.createFilter( group.getUsers(), \"order by this.name""\" ).list();]]>"msgstr ""#. Tag: title#: collection_mapping.xml:649#, no-c-formatmsgid "Bidirectional associations"msgstr "双向关联(Bidirectional associations)"#. Tag: para#: collection_mapping.xml:651#, fuzzy, no-c-formatmsgid """A <emphasis>bidirectional association</emphasis> allows navigation from both ""\"ends\" of the association. Two kinds of bidirectional association are ""supported:"msgstr """<emphasis>双向关联</emphasis>允许通过关联的任一端访问另外一端。在Hibernate""中, 支持两种类型的双向关联: <placeholder-1/>"#. Tag: term#: collection_mapping.xml:658#, no-c-formatmsgid "one-to-many"msgstr "一对多(one-to-many)"#. Tag: para#: collection_mapping.xml:660#, no-c-formatmsgid "set or bag valued at one end, single-valued at the other"msgstr "Set或者bag值在一端, 单独值(非集合)在另外一端"#. Tag: term#: collection_mapping.xml:666#, no-c-formatmsgid "many-to-many"msgstr "多对多(many-to-many)"#. Tag: para#: collection_mapping.xml:668#, no-c-formatmsgid "set or bag valued at both ends"msgstr "两端都是set或bag值"#. Tag: para#: collection_mapping.xml:677#, no-c-formatmsgid """You may specify a bidirectional many-to-many association simply by mapping ""two many-to-many associations to the same database table and declaring one ""end as <emphasis>inverse</emphasis> (which one is your choice, but it can ""not be an indexed collection)."msgstr """要建立一个双向的多对多关联,只需要映射两个many-to-many关联到同一个数据库表""中,并再定义其中的一端为<emphasis>inverse</emphasis>(使用哪一端要根据你的选""择,但它不能是一个索引集合)。"#. Tag: para#: collection_mapping.xml:684#, no-c-formatmsgid """Here's an example of a bidirectional many-to-many association; each category ""can have many items and each item can be in many categories:"msgstr """这里有一个many-to-many的双向关联的例子;每一个category都可以有很多items,每一个""items可以属于很多categories:"#. Tag: programlisting#: collection_mapping.xml:689#, no-c-formatmsgid """<![CDATA[<class name=\"Category\">\n"" <id name=\"id\" column=\"CATEGORY_ID\"/>\n"" ...\n"" <bag name=\"items\" table=\"CATEGORY_ITEM\">\n"" <key column=\"CATEGORY_ID\"/>\n"" <many-to-many class=\"Item\" column=\"ITEM_ID\"/>\n"" </bag>\n""</class>\n""\n""<class name=\"Item\">\n"" <id name=\"id\" column=\"ITEM_ID\"/>\n"" ...\n""\n"" <!-- inverse end -->\n"" <bag name=\"categories\" table=\"CATEGORY_ITEM\" inverse=\"true\">\n"" <key column=\"ITEM_ID\"/>\n"" <many-to-many class=\"Category\" column=\"CATEGORY_ID\"/>\n"" </bag>\n""</class>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:691#, no-c-formatmsgid """Changes made only to the inverse end of the association are <emphasis>not</""emphasis> persisted. This means that Hibernate has two representations in ""memory for every bidirectional association, one link from A to B and another ""link from B to A. This is easier to understand if you think about the Java ""object model and how we create a many-to-many relationship in Java:"msgstr """如果只对关联的反向端进行了改变,这个改变<emphasis>不会</emphasis>被持久化。 ""这表示Hibernate为每个双向关联在内存中存在两次表现,一个从A连接到B,另一个从B连""接到A。如果你回想一下Java对象模型,我们是如何在Java中创建多对多关系的,这可以""让你更容易理解:"#. Tag: programlisting#: collection_mapping.xml:699#, no-c-formatmsgid """<![CDATA[\n""category.getItems().add(item); // The category now \"knows\" about ""the relationship\n""item.getCategories().add(category); // The item now \"knows\" about the ""relationship\n""\n""session.persist(item); // The relationship won't be ""saved!\n""session.persist(category); // The relationship will be saved]]>"msgstr ""#. Tag: para#: collection_mapping.xml:701#, no-c-formatmsgid """The non-inverse side is used to save the in-memory representation to the ""database."msgstr "非反向端用于把内存中的表示保存到数据库中。"#. Tag: para#: collection_mapping.xml:705#, no-c-formatmsgid """You may define a bidirectional one-to-many association by mapping a one-to-""many association to the same table column(s) as a many-to-one association ""and declaring the many-valued end <literal>inverse=\"true\"</literal>."msgstr """要建立一个一对多的双向关联,你可以通过把一个一对多关联,作为一个多对一关联映""射到到同一张表的字段上,并且在\"多\"的那一端定义<literal>inverse=\"true\"</""literal>。"#. Tag: programlisting#: collection_mapping.xml:711#, no-c-formatmsgid """<![CDATA[<class name=\"Parent\">\n"" <id name=\"id\" column=\"parent_id\"/>\n"" ....\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\" column=\"child_id\"/>\n"" ....\n"" <many-to-one name=\"parent\" \n"" class=\"Parent\" \n"" column=\"parent_id\"\n"" not-null=\"true\"/>\n""</class>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:713#, no-c-formatmsgid """Mapping one end of an association with <literal>inverse=\"true\"</literal> ""doesn't affect the operation of cascades, these are orthogonal concepts!"msgstr """在“一”这一端定义<literal>inverse=\"true\"</literal>不会影响级联操作,二者是正""交的概念!"#. Tag: title#: collection_mapping.xml:721#, no-c-formatmsgid "Bidirectional associations with indexed collections"msgstr "双向关联,涉及有序集合类"#. Tag: para#: collection_mapping.xml:722#, no-c-formatmsgid """A bidirectional association where one end is represented as a <literal><""list></literal> or <literal><map></literal> requires special ""consideration. If there is a property of the child class which maps to the ""index column, no problem, we can continue using <literal>inverse=\"true\"</""literal> on the collection mapping:"msgstr """对于有一端是<literal><list></literal>或者<literal><map></literal>""的双向关联,需要加以特别考虑。假若子类中的一个属性映射到索引字段,没问题,我""们仍然可以在集合类映射上使用<literal>inverse=\"true\"</literal>:"#. Tag: programlisting#: collection_mapping.xml:729#, no-c-formatmsgid """<![CDATA[<class name=\"Parent\">\n"" <id name=\"id\" column=\"parent_id\"/>\n"" ....\n"" <map name=\"children\" inverse=\"true\">\n"" <key column=\"parent_id\"/>\n"" <map-key column=\"name\" \n"" type=\"string\"/>\n"" <one-to-many class=\"Child\"/>\n"" </map>\n""</class>\n""\n""<class name=\"Child\">\n"" <id name=\"id\" column=\"child_id\"/>\n"" ....\n"" <property name=\"name\" \n"" not-null=\"true\"/>\n"" <many-to-one name=\"parent\" \n"" class=\"Parent\" \n"" column=\"parent_id\"\n"" not-null=\"true\"/>\n""</class>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:731#, no-c-formatmsgid """But, if there is no such property on the child class, we can't think of the ""association as truly bidirectional (there is information available at one ""end of the association that is not available at the other end). In this ""case, we can't map the collection <literal>inverse=\"true\"</literal>. ""Instead, we could use the following mapping:"msgstr """但是,假若子类中没有这样的属性存在,我们不能认为这个关联是真正的双向关联(信""息不对称,在关联的一端有一些另外一端没有的信息)。在这种情况下,我们不能使用""<literal>inverse=\"true\"</literal>。我们需要这样用:"#. Tag: programlisting#: collection_mapping.xml:738#, no-c-formatmsgid """<![CDATA[<class name=\"Parent\">\n"" <id name=\"id\" column=\"parent_id\"/>\n"" ....\n"" <map name=\"children\">\n"" <key column=\"parent_id\"\n"" not-null=\"true\"/>\n"" <map-key column=\"name\" \n"" type=\"string\"/>\n"" <one-to-many class=\"Child\"/>\n"" </map>\n""</class>\n""\n""<class name=\"Child\">\n"" <id name=\"id\" column=\"child_id\"/>\n"" ....\n"" <many-to-one name=\"parent\" \n"" class=\"Parent\" \n"" column=\"parent_id\"\n"" insert=\"false\"\n"" update=\"false\"\n"" not-null=\"true\"/>\n""</class>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:740#, no-c-formatmsgid """Note that in this mapping, the collection-valued end of the association is ""responsible for updates to the foreign key. TODO: Does this really result in ""some unnecessary update statements?"msgstr """注意在这个映射中,关联中集合类\"值\"一端负责来更新外键.TODO: Does this ""really result in some unnecessary update statements?"#. Tag: title#: collection_mapping.xml:748#, no-c-formatmsgid "Ternary associations"msgstr "三重关联(Ternary associations)"#. Tag: para#: collection_mapping.xml:750#, no-c-formatmsgid """There are three possible approaches to mapping a ternary association. One is ""to use a <literal>Map</literal> with an association as its index:"msgstr """有三种可能的途径来映射一个三重关联。第一种是使用一个<literal>Map</literal>,""把一个关联作为其索引:"#. Tag: programlisting#: collection_mapping.xml:755#, no-c-formatmsgid """<![CDATA[<map name=\"contracts\">\n"" <key column=\"employer_id\" not-null=\"true\"/>\n"" <map-key-many-to-many column=\"employee_id\" class=\"Employee\"/>\n"" <one-to-many class=\"Contract\"/>\n""</map>]]>"msgstr ""#. Tag: programlisting#: collection_mapping.xml:757#, no-c-formatmsgid """<![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:759#, 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:764#, no-c-formatmsgid """A final alternative is to use composite elements, which we will discuss ""later."msgstr "最后一种选择是使用复合元素,我们会在后面讨论"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -