📄 collection_mapping.pot
字号:
#: collection_mapping.xml:547(para) msgid "<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."msgstr ""#: collection_mapping.xml:556(para) msgid "Some examples, first, a set of strings:"msgstr ""#: collection_mapping.xml:565(para) msgid "A bag containing integers (with an iteration order determined by the <literal>order-by</literal> attribute):"msgstr ""#: collection_mapping.xml:577(para) msgid "An array of entities - in this case, a many to many association:"msgstr ""#: collection_mapping.xml:589(para) msgid "A map from string indices to dates:"msgstr ""#: collection_mapping.xml:602(para) msgid "A list of components (discussed in the next chapter):"msgstr ""#: collection_mapping.xml:620(title) msgid "One-to-many associations"msgstr ""#: collection_mapping.xml:622(para) msgid "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 ""#: collection_mapping.xml:630(para) msgid "An instance of the contained entity class may not belong to more than one instance of the collection"msgstr ""#: collection_mapping.xml:636(para) msgid "An instance of the contained entity class may not appear at more than one value of the collection index"msgstr ""#: collection_mapping.xml:643(para) msgid "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 ""#: collection_mapping.xml:670(para) msgid "<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 ""#: collection_mapping.xml:685(para) msgid "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 ""#: collection_mapping.xml:691(para) msgid "<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 ""#: collection_mapping.xml:700(para) msgid "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 ""#: collection_mapping.xml:717(title) msgid "Advanced collection mappings"msgstr ""#: collection_mapping.xml:720(title) msgid "Sorted collections"msgstr ""#: collection_mapping.xml:722(para) msgid "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 ""#: collection_mapping.xml:740(para) msgid "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 ""#: collection_mapping.xml:746(para) msgid "Sorted collections actually behave like <literal>java.util.TreeSet</literal> or <literal>java.util.TreeMap</literal>."msgstr ""#: collection_mapping.xml:751(para) msgid "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 ""#: collection_mapping.xml:771(para) msgid "Note that the value of the <literal>order-by</literal> attribute is an SQL ordering, not a HQL ordering!"msgstr ""#: collection_mapping.xml:776(para) msgid "Associations may even be sorted by some arbitrary criteria at runtime using a collection <literal>filter()</literal>."msgstr ""#: collection_mapping.xml:786(title) msgid "Bidirectional associations"msgstr ""#: collection_mapping.xml:795(term) msgid "one-to-many"msgstr ""#: collection_mapping.xml:797(para) msgid "set or bag valued at one end, single-valued at the other"msgstr ""#: collection_mapping.xml:803(term) msgid "many-to-many"msgstr ""#: collection_mapping.xml:805(para) msgid "set or bag valued at both ends"msgstr ""#: collection_mapping.xml:788(para) msgid "A <emphasis>bidirectional association</emphasis> allows navigation from both \"ends\" of the association. Two kinds of bidirectional association are supported: <placeholder-1/>"msgstr ""#: collection_mapping.xml:814(para) msgid "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 ""#: collection_mapping.xml:821(para) msgid "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 ""#: collection_mapping.xml:846(para) msgid "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 ""#: collection_mapping.xml:861(para) msgid "The non-inverse side is used to save the in-memory representation to the database."msgstr ""#: collection_mapping.xml:865(para) msgid "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 ""#: collection_mapping.xml:889(para) msgid "Mapping one end of an association with <literal>inverse=\"true\"</literal> doesn't affect the operation of cascades, these are orthogonal concepts!"msgstr ""#: collection_mapping.xml:897(title) msgid "Bidirectional associations with indexed collections"msgstr ""#: collection_mapping.xml:898(para) msgid "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 ""#: collection_mapping.xml:927(para) msgid "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 ""#: collection_mapping.xml:957(para) msgid "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 ""#: collection_mapping.xml:965(title) msgid "Ternary associations"msgstr ""#: collection_mapping.xml:967(para) msgid "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 ""#: collection_mapping.xml:984(para) msgid "A second approach is to simply remodel the association as an entity class. This is the approach we use most commonly."msgstr ""#: collection_mapping.xml:989(para) msgid "A final alternative is to use composite elements, which we will discuss later."msgstr ""#: collection_mapping.xml:996(literal) msgid "Using an <idbag>"msgstr ""#: collection_mapping.xml:998(para) msgid "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 ""#: collection_mapping.xml:1009(para) msgid "The <literal><idbag></literal> element lets you map a <literal>List</literal> (or <literal>Collection</literal>) with bag semantics."msgstr ""#: collection_mapping.xml:1022(para) msgid "As you can see, an <literal><idbag></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 ""#: collection_mapping.xml:1029(para) msgid "Note that the update performance of an <literal><idbag></literal> is <emphasis>much</emphasis> better than a regular <literal><bag></literal>! Hibernate can locate individual rows efficiently and update or delete them individually, just like a list, map or set."msgstr ""#: collection_mapping.xml:1036(para) msgid "In the current implementation, the <literal>native</literal> identifier generation strategy is not supported for <literal><idbag></literal> collection identifiers."msgstr ""#: collection_mapping.xml:1060(title) msgid "Collection examples"msgstr ""#: collection_mapping.xml:1062(para) msgid "The previous sections are pretty confusing. So lets look at an example. This class:"msgstr ""#: collection_mapping.xml:1084(para) msgid "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 ""#: collection_mapping.xml:1111(para) msgid "This maps to the following table definitions:"msgstr ""#: collection_mapping.xml:1119(para) msgid "If the parent is <emphasis>required</emphasis>, use a bidirectional one-to-many association:"msgstr ""#: collection_mapping.xml:1146(para) msgid "Notice the <literal>NOT NULL</literal> constraint:"msgstr ""#: collection_mapping.xml:1157(para) msgid "Alternatively, if you absolutely insist that this association should be unidirectional, you can declare the <literal>NOT NULL</literal> constraint on the <literal><key></literal> mapping:"msgstr ""#: collection_mapping.xml:1184(para) msgid "On the other hand, if a child might have multiple parents, a many-to-many association is appropriate:"msgstr ""#: collection_mapping.xml:1210(para) msgid "Table definitions:"msgstr ""#: collection_mapping.xml:1222(para) msgid "For more examples and a complete walk-through a parent/child relationship mapping, see <xref linkend=\"example-parentchild\"/>."msgstr ""#: collection_mapping.xml:1227(para) msgid "Even more exotic association mappings are possible, we will catalog all possibilities in the next chapter."msgstr ""#. Put one translator per line, in the form of NAME <EMAIL>, YEAR1, YEAR2.#: collection_mapping.xml:0(None) msgid "translator-credits"msgstr ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -