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

📄 collection_mapping.pot

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 POT
📖 第 1 页 / 共 4 页
字号:
      "    <element column=\"name\" type=\"string\"/>\n"      "</set>\n"      "\n"      "<map name=\"holidays\" sort=\"my.custom.HolidayComparator\">\n"      "    <key column=\"year_id\"/>\n"      "    <map-key column=\"hol_name\" type=\"string\"/>\n"      "    <element column=\"hol_date\" type=\"date\"/>\n"      "</map>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:638#, no-c-formatmsgid "Allowed values of the <literal>sort</literal> attribute are <literal>unsorted</literal>, <literal>natural</literal> and the name of a class implementing <literal>java.util.Comparator</literal>."msgstr ""#. Tag: para#: collection_mapping.xml:644#, no-c-formatmsgid "Sorted collections actually behave like <literal>java.util.TreeSet</literal> or <literal>java.util.TreeMap</literal>."msgstr ""#. Tag: para#: collection_mapping.xml:649#, no-c-formatmsgid "If you want the database itself to order the collection elements use the <literal>order-by</literal> attribute of <literal>set</literal>, <literal>bag</literal> or <literal>map</literal> mappings. This solution is only available under JDK 1.4 or higher (it is implemented using <literal>LinkedHashSet</literal> or <literal>LinkedHashMap</literal>). This performs the ordering in the SQL query, not in memory."msgstr ""#. Tag: programlisting#: collection_mapping.xml:658#, no-c-formatmsgid ""      "<![CDATA[<set name=\"aliases\" table=\"person_aliases\" order-by=\"lower(name) asc\">\n"      "    <key column=\"person\"/>\n"      "    <element column=\"name\" type=\"string\"/>\n"      "</set>\n"      "\n"      "<map name=\"holidays\" order-by=\"hol_date, hol_name\">\n"      "    <key column=\"year_id\"/>\n"      "    <map-key column=\"hol_name\" type=\"string\"/>\n"      "    <element column=\"hol_date type=\"date\"/>\n"      "</map>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:660#, no-c-formatmsgid "Note that the value of the <literal>order-by</literal> attribute is an SQL ordering, not a HQL ordering!"msgstr ""#. Tag: para#: collection_mapping.xml:665#, no-c-formatmsgid "Associations may even be sorted by some arbitrary criteria at runtime using a collection <literal>filter()</literal>."msgstr ""#. Tag: programlisting#: collection_mapping.xml:670#, no-c-formatmsgid "<![CDATA[sortedUsers = s.createFilter( group.getUsers(), \"order by this.name\" ).list();]]>"msgstr ""#. Tag: title#: collection_mapping.xml:675#, no-c-formatmsgid "Bidirectional associations"msgstr ""#. Tag: para#: collection_mapping.xml:677#, no-c-formatmsgid "A <emphasis>bidirectional association</emphasis> allows navigation from both \"ends\" of the association. Two kinds of bidirectional association are supported:"msgstr ""#. Tag: term#: collection_mapping.xml:684#, no-c-formatmsgid "one-to-many"msgstr ""#. Tag: para#: collection_mapping.xml:686#, no-c-formatmsgid "set or bag valued at one end, single-valued at the other"msgstr ""#. Tag: term#: collection_mapping.xml:692#, no-c-formatmsgid "many-to-many"msgstr ""#. Tag: para#: collection_mapping.xml:694#, no-c-formatmsgid "set or bag valued at both ends"msgstr ""#. Tag: para#: collection_mapping.xml:703#, 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 ""#. Tag: para#: collection_mapping.xml:710#, 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 ""#. Tag: programlisting#: collection_mapping.xml:715#, 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:717#, 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 ""#. Tag: programlisting#: collection_mapping.xml:725#, 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:727#, no-c-formatmsgid "The non-inverse side is used to save the in-memory representation to the database."msgstr ""#. Tag: para#: collection_mapping.xml:731#, 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 ""#. Tag: programlisting#: collection_mapping.xml:737#, 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:739#, 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 ""#. Tag: title#: collection_mapping.xml:747#, no-c-formatmsgid "Bidirectional associations with indexed collections"msgstr ""#. Tag: para#: collection_mapping.xml:748#, no-c-formatmsgid "A bidirectional association where one end is represented as a <literal>&lt;list&gt;</literal> or <literal>&lt;map&gt;</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 ""#. Tag: programlisting#: collection_mapping.xml:755#, 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:757#, 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 ""#. Tag: programlisting#: collection_mapping.xml:764#, 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:766#, 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 ""#. Tag: title#: collection_mapping.xml:774#, no-c-formatmsgid "Ternary associations"msgstr ""#. Tag: para#: collection_mapping.xml:776#, 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 ""#. Tag: programlisting#: collection_mapping.xml:781#, 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:783#, no-c-format

⌨️ 快捷键说明

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