📄 collection_mapping.pot
字号:
#: collection_mapping.xml:274#, no-c-formatmsgid "The contained type is referred to as the <emphasis>collection element type</emphasis>. Collection elements are mapped by <literal><element></literal> or <literal><composite-element></literal>, or in the case of entity references, with <literal><one-to-many></literal> or <literal><many-to-many></literal>. The first two map elements with value semantics, the next two are used to map entity associations."msgstr ""#. Tag: title#: collection_mapping.xml:286#, no-c-formatmsgid "Indexed collections"msgstr ""#. Tag: para#: collection_mapping.xml:288#, no-c-formatmsgid "All collection mappings, except those with set and bag semantics, need an <emphasis>index column</emphasis> in the collection table - a column that maps to an array index, or <literal>List</literal> index, or <literal>Map</literal> key. The index of a <literal>Map</literal> may be of any basic type, mapped with <literal><map-key></literal>, it may be an entity reference mapped with <literal><map-key-many-to-many></literal>, or it may be a composite type, mapped with <literal><composite-map-key></literal>. The index of an array or list is always of type <literal>integer</literal> and is mapped using the <literal><list-index></literal> element. The mapped column contains sequential integers (numbered from zero, by default)."msgstr ""#. Tag: sect2#: collection_mapping.xml:299#, no-c-formatmsgid "" "<programlistingco> <areaspec> <area id=\"index1\" coords=\"2 45\"/> <area id=\"index2\" coords=\"3 45\"/> </areaspec> <programlisting><![CDATA[<list-index \n" " column=\"column_name\"\n" " base=\"0|1|...\"/>]]></programlisting> <calloutlist> <callout arearefs=\"index1\"> <para> <literal>column_name</literal> (required): The name of the column holding the collection index values. </para> </callout> <callout arearefs=\"index1\"> <para> <literal>base</literal> (optional, defaults to <literal>0</literal>): The value of the index column that corresponds to the first element of the list or array. </para> </callout> </calloutlist> </programlistingco> <programlistingco> <areaspec> <area id=\"mapkey1\" coords=\"2 45\"/> <area id=\"mapkey2\" coords=\"3 45\"/> <area id=\"mapkey3\" coords=\"4 45\"/> </areaspec> <programlisting><![CDATA[<map-key \n" " column=\"column_name\"\n" " formula=\"any SQL expression\"\n" " type=\"type_name\"\n" " node=\"@attribute-name\"\n" " length=\"N\"/>]]></programlisting> <calloutlist> <callout arearefs=\"mapkey1\"> <para> <literal>column</literal> (optional): The name of the column holding the collection index values. </para> </callout> <callout arearefs=\"mapkey2\"> <para> <literal>formula</literal> (optional): A SQL formula used to evaluate the key of the map. </para> </callout> <callout arearefs=\"mapkey3\"> <para> <literal>type</literal> (reguired): The type of the map keys. </para> </callout> </calloutlist> </programlistingco> <programlistingco> <areaspec> <area id=\"indexmanytomany1\" coords=\"2 45\"/> <area id=\"indexmanytomany2\" coords=\"3 45\"/> <area id=\"indexmanytomany3\" coords=\"3 45\"/> </areaspec> <programlisting><![CDATA[<map-key-many-to-many\n" " column=\"column_name\"\n" " formula=\"any SQL expression\"\n" " class=\"ClassName\"\n" "/>]]></programlisting> <calloutlist> <callout arearefs=\"indexmanytomany1\"> <para> <literal>column</literal> (optional): The name of the foreign key column for the collection index values. </para> </callout> <callout arearefs=\"indexmanytomany2\"> <para> <literal>formula</literal> (optional): A SQL formula used to evaluate the foreign key of the map key. </para> </callout> <callout arearefs=\"indexmanytomany3\"> <para> <literal>class</literal> (required): The entity class used as the map key. </para> </callout> </calloutlist> </programlistingco>"msgstr ""#. Tag: para#: collection_mapping.xml:380#, no-c-formatmsgid "If your table doesn't have an index column, and you still wish to use <literal>List</literal> as the property type, you should map the property as a Hibernate <emphasis><bag></emphasis>. A bag does not retain its order when it is retrieved from the database, but it may be optionally sorted or ordered."msgstr ""#. Tag: title#: collection_mapping.xml:390#, no-c-formatmsgid "Collections of values and many-to-many associations"msgstr ""#. Tag: para#: collection_mapping.xml:392#, no-c-formatmsgid "Any collection of values or many-to-many association requires a dedicated <emphasis>collection table</emphasis> with a foreign key column or columns, <emphasis>collection element column</emphasis> or columns and possibly an index column or columns."msgstr ""#. Tag: para#: collection_mapping.xml:399#, no-c-formatmsgid "For a collection of values, we use the <literal><element></literal> tag."msgstr ""#. Tag: sect2#: collection_mapping.xml:401#, no-c-formatmsgid "" "<programlistingco> <areaspec> <area id=\"element1b\" coords=\"2 50\"/> <area id=\"element2b\" coords=\"3 50\"/> <area id=\"element3b\" coords=\"4 50\"/> </areaspec> <programlisting><![CDATA[<element\n" " column=\"column_name\"\n" " formula=\"any SQL expression\"\n" " type=\"typename\"\n" " length=\"L\"\n" " precision=\"P\"\n" " scale=\"S\"\n" " not-null=\"true|false\"\n" " unique=\"true|false\"\n" " node=\"element-name\"\n" "/>]]></programlisting> <calloutlist> <callout arearefs=\"element1b\"> <para> <literal>column</literal> (optional): The name of the column holding the collection element values. </para> </callout> <callout arearefs=\"element2b\"> <para> <literal>formula</literal> (optional): An SQL formula used to evaluate the element. </para> </callout> <callout arearefs=\"element3b\"> <para> <literal>type</literal> (required): The type of the collection element. </para> </callout> </calloutlist> </programlistingco> <para> A <emphasis>many-to-many association</emphasis> is specified using the <literal><many-to-many></literal> element. </para> <programlistingco> <areaspec> <area id=\"manytomany1\" coords=\"2 60\"/> <area id=\"manytomany2\" coords=\"3 60\"/> <area id=\"manytomany3\" coords=\"4 60\"/> <area id=\"manytomany4\" coords=\"5 60\"/> <area id=\"manytomany5\" coords=\"6 60\"/> <area id=\"manytomany6\" coords=\"7 60\"/> <area id=\"manytomany7\" coords=\"8 60\"/> <area id=\"manytomany8\" coords=\"9 60\"/> </areaspec> <programlisting><![CDATA[<many-to-many\n" " column=\"column_name\"\n" " formula=\"any SQL expression\"\n" " class=\"ClassName\"\n" " fetch=\"select|join\"\n" " unique=\"true|false\"\n" " not-found=\"ignore|exception\"\n" " entity-name=\"EntityName\"\n" " property-ref=\"propertyNameFromAssociatedClass\"\n" " node=\"element-name\"\n" " embed-xml=\"true|false\"\n" " />]]></programlisting> <calloutlist> <callout arearefs=\"manytomany1\"> <para> <literal>column</literal> (optional): The name of the element foreign key column. </para> </callout> <callout arearefs=\"manytomany2\"> <para> <literal>formula</literal> (optional): An SQL formula used to evaluate the element foreign key value. </para> </callout> <callout arearefs=\"manytomany3\"> <para> <literal>class</literal> (required): The name of the associated class. </para> </callout> <callout arearefs=\"manytomany4\"> <para> <literal>fetch</literal> (optional - defaults to <literal>join</literal>): enables outer-join or sequential select fetching for this association. This is a special case; for full eager fetching (in a single <literal>SELECT</literal>) of an entity and its many-to-many relationships to other entities, you would enable <literal>join</literal> fetching not only of the collection itself, but also with this attribute on the <literal><many-to-many></literal> nested element. </para> </callout> <callout arearefs=\"manytomany5\"> <para> <literal>unique</literal> (optional): Enable the DDL generation of a unique constraint for the foreign-key column. This makes the association multiplicity effectively one to many. </para> </callout> <callout arearefs=\"manytomany6\"> <para> <literal>not-found</literal> (optional - defaults to <literal>exception</literal>): Specifies how foreign keys that reference missing rows will be handled: <literal>ignore</literal> will treat a missing row as a null association. </para> </callout> <callout arearefs=\"manytomany7\"> <para> <literal>entity-name</literal> (optional): The entity name of the associated class, as an alternative to <literal>class</literal>. </para> </callout> <callout arearefs=\"manytomany8\"> <para> <literal>property-ref</literal>: (optional) The name of a property of the associated class that is joined to this foreign key. If not specified, the primary key of the associated class is used. </para> </callout> </calloutlist> </programlistingco>"msgstr ""#. Tag: para#: collection_mapping.xml:506#, no-c-formatmsgid "Some examples, first, a set of strings:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:510#, no-c-formatmsgid "" "<![CDATA[<set name=\"names\" table=\"person_names\">\n" " <key column=\"person_id\"/>\n" " <element column=\"person_name\" type=\"string\"/>\n" "</set>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:512#, no-c-formatmsgid "A bag containing integers (with an iteration order determined by the <literal>order-by</literal> attribute):"msgstr ""#. Tag: programlisting#: collection_mapping.xml:517#, no-c-formatmsgid "" "<![CDATA[<bag name=\"sizes\" \n" " table=\"item_sizes\" \n" " order-by=\"size asc\">\n" " <key column=\"item_id\"/>\n" " <element column=\"size\" type=\"integer\"/>\n" "</bag>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:519#, no-c-formatmsgid "An array of entities - in this case, a many to many association:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:523#, no-c-formatmsgid "" "<![CDATA[<array name=\"addresses\" \n" " table=\"PersonAddress\" \n" " cascade=\"persist\">\n" " <key column=\"personId\"/>\n" " <list-index column=\"sortOrder\"/>\n" " <many-to-many column=\"addressId\" class=\"Address\"/>\n" "</array>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:525#, no-c-formatmsgid "A map from string indices to dates:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:529#, no-c-formatmsgid "" "<![CDATA[<map name=\"holidays\" \n" " table=\"holidays\" \n" " schema=\"dbo\" \n" " order-by=\"hol_name asc\">\n" " <key column=\"id\"/>\n" " <map-key column=\"hol_name\" type=\"string\"/>\n" " <element column=\"hol_date\" type=\"date\"/>\n" "</map>]]>"msgstr ""#. Tag: para#: collection_mapping.xml:531#, no-c-formatmsgid "A list of components (discussed in the next chapter):"msgstr ""#. Tag: programlisting#: collection_mapping.xml:535#, no-c-formatmsgid "" "<![CDATA[<list name=\"carComponents\" \n" " table=\"CarComponents\">\n" " <key column=\"carId\"/>\n" " <list-index column=\"sortOrder\"/>\n" " <composite-element class=\"CarComponent\">\n" " <property name=\"price\"/>\n" " <property name=\"type\"/>\n" " <property name=\"serialNumber\" column=\"serialNum\"/>\n" " </composite-element>\n" "</list>]]>"msgstr ""#. Tag: title#: collection_mapping.xml:540#, no-c-formatmsgid "One-to-many associations"msgstr ""#. Tag: para#: collection_mapping.xml:542#, no-c-formatmsgid "A <emphasis>one to many association</emphasis> links the tables of two classes via a foreign key, with no intervening collection table. This mapping loses certain semantics of normal Java collections:"msgstr ""#. Tag: para#: collection_mapping.xml:550#, no-c-formatmsgid "An instance of the contained entity class may not belong to more than one instance of the collection"msgstr ""#. Tag: para#: collection_mapping.xml:556#, no-c-formatmsgid "An instance of the contained entity class may not appear at more than one value of the collection index"msgstr ""#. Tag: para#: collection_mapping.xml:563#, no-c-formatmsgid "An association from <literal>Product</literal> to <literal>Part</literal> requires existence of a foreign key column and possibly an index column to the <literal>Part</literal> table. A <literal><one-to-many></literal> tag indicates that this is a one to many association."msgstr ""#. Tag: programlisting#: collection_mapping.xml:576#, no-c-formatmsgid "" "<![CDATA[<one-to-many \n" " class=\"ClassName\"\n" " not-found=\"ignore|exception\"\n" " entity-name=\"EntityName\"\n" " node=\"element-name\"\n" " embed-xml=\"true|false\"\n" " />]]>"msgstr ""#. Tag: para#: collection_mapping.xml:579#, no-c-formatmsgid "<literal>class</literal> (required): The name of the associated class."msgstr ""#. Tag: para#: collection_mapping.xml:584#, no-c-formatmsgid "<literal>not-found</literal> (optional - defaults to <literal>exception</literal>): Specifies how cached identifiers that reference missing rows will be handled: <literal>ignore</literal> will treat a missing row as a null association."msgstr ""#. Tag: para#: collection_mapping.xml:591#, no-c-formatmsgid "<literal>entity-name</literal> (optional): The entity name of the associated class, as an alternative to <literal>class</literal>."msgstr ""#. Tag: para#: collection_mapping.xml:599#, no-c-formatmsgid "Notice that the <literal><one-to-many></literal> element does not need to declare any columns. Nor is it necessary to specify the <literal>table</literal> name anywhere."msgstr ""#. Tag: para#: collection_mapping.xml:605#, no-c-formatmsgid "<emphasis>Very important note:</emphasis> If the foreign key column of a <literal><one-to-many></literal> association is declared <literal>NOT NULL</literal>, you must declare the <literal><key></literal> mapping <literal>not-null=\"true\"</literal> or <emphasis>use a bidirectional association</emphasis> with the collection mapping marked <literal>inverse=\"true\"</literal>. See the discussion of bidirectional associations later in this chapter."msgstr ""#. Tag: para#: collection_mapping.xml:614#, no-c-formatmsgid "This example shows a map of <literal>Part</literal> entities by name (where <literal>partName</literal> is a persistent property of <literal>Part</literal>). Notice the use of a formula-based index."msgstr ""#. Tag: programlisting#: collection_mapping.xml:620#, no-c-formatmsgid "" "<![CDATA[<map name=\"parts\"\n" " cascade=\"all\">\n" " <key column=\"productId\" not-null=\"true\"/>\n" " <map-key formula=\"partName\"/>\n" " <one-to-many class=\"Part\"/>\n" "</map>]]>"msgstr ""#. Tag: title#: collection_mapping.xml:626#, no-c-formatmsgid "Advanced collection mappings"msgstr ""#. Tag: title#: collection_mapping.xml:629#, no-c-formatmsgid "Sorted collections"msgstr ""#. Tag: para#: collection_mapping.xml:631#, no-c-formatmsgid "Hibernate supports collections implementing <literal>java.util.SortedMap</literal> and <literal>java.util.SortedSet</literal>. You must specify a comparator in the mapping file:"msgstr ""#. Tag: programlisting#: collection_mapping.xml:636#, no-c-formatmsgid "" "<![CDATA[<set name=\"aliases\" \n" " table=\"person_aliases\" \n" " sort=\"natural\">\n" " <key column=\"person\"/>\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -