📄 inheritance_mapping.pot
字号:
#. Tag: para#: inheritance_mapping.xml:194#, no-c-formatmsgid "The limitation of this approach is that if a property is mapped on the superclass, the column name must be the same on all subclass tables. (We might relax this in a future release of Hibernate.) The identity generator strategy is not allowed in union subclass inheritance, indeed the primary key seed has to be shared accross all unioned subclasses of a hierarchy."msgstr ""#. Tag: para#: inheritance_mapping.xml:203#, no-c-formatmsgid "If your superclass is abstract, map it with <literal>abstract=\"true\"</literal>. Of course, if it is not abstract, an additional table (defaults to <literal>PAYMENT</literal> in the example above) is needed to hold instances of the superclass."msgstr ""#. Tag: title#: inheritance_mapping.xml:213#, no-c-formatmsgid "Table per concrete class, using implicit polymorphism"msgstr ""#. Tag: para#: inheritance_mapping.xml:215#, no-c-formatmsgid "An alternative approach is to make use of implicit polymorphism:"msgstr ""#. Tag: programlisting#: inheritance_mapping.xml:219#, no-c-formatmsgid "" "<![CDATA[<class name=\"CreditCardPayment\" table=\"CREDIT_PAYMENT\">\n" " <id name=\"id\" type=\"long\" column=\"CREDIT_PAYMENT_ID\">\n" " <generator class=\"native\"/>\n" " </id>\n" " <property name=\"amount\" column=\"CREDIT_AMOUNT\"/>\n" " ...\n" "</class>\n" "\n" "<class name=\"CashPayment\" table=\"CASH_PAYMENT\">\n" " <id name=\"id\" type=\"long\" column=\"CASH_PAYMENT_ID\">\n" " <generator class=\"native\"/>\n" " </id>\n" " <property name=\"amount\" column=\"CASH_AMOUNT\"/>\n" " ...\n" "</class>\n" "\n" "<class name=\"ChequePayment\" table=\"CHEQUE_PAYMENT\">\n" " <id name=\"id\" type=\"long\" column=\"CHEQUE_PAYMENT_ID\">\n" " <generator class=\"native\"/>\n" " </id>\n" " <property name=\"amount\" column=\"CHEQUE_AMOUNT\"/>\n" " ...\n" "</class>]]>"msgstr ""#. Tag: para#: inheritance_mapping.xml:221#, no-c-formatmsgid "Notice that nowhere do we mention the <literal>Payment</literal> interface explicitly. Also notice that properties of <literal>Payment</literal> are mapped in each of the subclasses. If you want to avoid duplication, consider using XML entities (e.g. <literal>[ <!ENTITY allproperties SYSTEM \"allproperties.xml\"> ]</literal> in the <literal>DOCTYPE</literal> declartion and <literal>&allproperties;</literal> in the mapping)."msgstr ""#. Tag: para#: inheritance_mapping.xml:231#, no-c-formatmsgid "The disadvantage of this approach is that Hibernate does not generate SQL <literal>UNION</literal>s when performing polymorphic queries."msgstr ""#. Tag: para#: inheritance_mapping.xml:236#, no-c-formatmsgid "For this mapping strategy, a polymorphic association to <literal>Payment</literal> is usually mapped using <literal><any></literal>."msgstr ""#. Tag: programlisting#: inheritance_mapping.xml:241#, no-c-formatmsgid "" "<![CDATA[<any name=\"payment\" meta-type=\"string\" id-type=\"long\">\n" " <meta-value value=\"CREDIT\" class=\"CreditCardPayment\"/>\n" " <meta-value value=\"CASH\" class=\"CashPayment\"/>\n" " <meta-value value=\"CHEQUE\" class=\"ChequePayment\"/>\n" " <column name=\"PAYMENT_CLASS\"/>\n" " <column name=\"PAYMENT_ID\"/>\n" "</any>]]>"msgstr ""#. Tag: title#: inheritance_mapping.xml:246#, no-c-formatmsgid "Mixing implicit polymorphism with other inheritance mappings"msgstr ""#. Tag: para#: inheritance_mapping.xml:248#, no-c-formatmsgid "There is one further thing to notice about this mapping. Since the subclasses are each mapped in their own <literal><class></literal> element (and since <literal>Payment</literal> is just an interface), each of the subclasses could easily be part of another inheritance hierarchy! (And you can still use polymorphic queries against the <literal>Payment</literal> interface.)"msgstr ""#. Tag: programlisting#: inheritance_mapping.xml:256#, no-c-formatmsgid "" "<![CDATA[<class name=\"CreditCardPayment\" table=\"CREDIT_PAYMENT\">\n" " <id name=\"id\" type=\"long\" column=\"CREDIT_PAYMENT_ID\">\n" " <generator class=\"native\"/>\n" " </id>\n" " <discriminator column=\"CREDIT_CARD\" type=\"string\"/>\n" " <property name=\"amount\" column=\"CREDIT_AMOUNT\"/>\n" " ...\n" " <subclass name=\"MasterCardPayment\" discriminator-value=\"MDC\"/>\n" " <subclass name=\"VisaPayment\" discriminator-value=\"VISA\"/>\n" "</class>\n" "\n" "<class name=\"NonelectronicTransaction\" table=\"NONELECTRONIC_TXN\">\n" " <id name=\"id\" type=\"long\" column=\"TXN_ID\">\n" " <generator class=\"native\"/>\n" " </id>\n" " ...\n" " <joined-subclass name=\"CashPayment\" table=\"CASH_PAYMENT\">\n" " <key column=\"PAYMENT_ID\"/>\n" " <property name=\"amount\" column=\"CASH_AMOUNT\"/>\n" " ...\n" " </joined-subclass>\n" " <joined-subclass name=\"ChequePayment\" table=\"CHEQUE_PAYMENT\">\n" " <key column=\"PAYMENT_ID\"/>\n" " <property name=\"amount\" column=\"CHEQUE_AMOUNT\"/>\n" " ...\n" " </joined-subclass>\n" "</class>]]>"msgstr ""#. Tag: para#: inheritance_mapping.xml:258#, no-c-formatmsgid "Once again, we don't mention <literal>Payment</literal> explicitly. If we execute a query against the <literal>Payment</literal> interface - for example, <literal>from Payment</literal> - Hibernate automatically returns instances of <literal>CreditCardPayment</literal> (and its subclasses, since they also implement <literal>Payment</literal>), <literal>CashPayment</literal> and <literal>ChequePayment</literal> but not instances of <literal>NonelectronicTransaction</literal>."msgstr ""#. Tag: title#: inheritance_mapping.xml:273#, no-c-formatmsgid "Limitations"msgstr ""#. Tag: para#: inheritance_mapping.xml:275#, no-c-formatmsgid "There are certain limitations to the \"implicit polymorphism\" approach to the table per concrete-class mapping strategy. There are somewhat less restrictive limitations to <literal><union-subclass></literal> mappings."msgstr ""#. Tag: para#: inheritance_mapping.xml:282#, no-c-formatmsgid "The following table shows the limitations of table per concrete-class mappings, and of implicit polymorphism, in Hibernate."msgstr ""#. Tag: title#: inheritance_mapping.xml:288#, no-c-formatmsgid "Features of inheritance mappings"msgstr ""#. Tag: entry#: inheritance_mapping.xml:300#, no-c-formatmsgid "Inheritance strategy"msgstr ""#. Tag: entry#: inheritance_mapping.xml:301#, no-c-formatmsgid "Polymorphic many-to-one"msgstr ""#. Tag: entry#: inheritance_mapping.xml:302#, no-c-formatmsgid "Polymorphic one-to-one"msgstr ""#. Tag: entry#: inheritance_mapping.xml:303#, no-c-formatmsgid "Polymorphic one-to-many"msgstr ""#. Tag: entry#: inheritance_mapping.xml:304#, no-c-formatmsgid "Polymorphic many-to-many"msgstr ""#. Tag: entry#: inheritance_mapping.xml:305#, no-c-formatmsgid "Polymorphic <literal>load()/get()</literal>"msgstr ""#. Tag: entry#: inheritance_mapping.xml:306#, no-c-formatmsgid "Polymorphic queries"msgstr ""#. Tag: entry#: inheritance_mapping.xml:307#, no-c-formatmsgid "Polymorphic joins"msgstr ""#. Tag: entry#: inheritance_mapping.xml:308#, no-c-formatmsgid "Outer join fetching"msgstr ""#. Tag: entry#: inheritance_mapping.xml:313#, no-c-formatmsgid "table per class-hierarchy"msgstr ""#. Tag: literal#: inheritance_mapping.xml:314 inheritance_mapping.xml:325 inheritance_mapping.xml:336#, no-c-formatmsgid "<many-to-one>"msgstr ""#. Tag: literal#: inheritance_mapping.xml:315 inheritance_mapping.xml:326 inheritance_mapping.xml:337#, no-c-formatmsgid "<one-to-one>"msgstr ""#. Tag: literal#: inheritance_mapping.xml:316 inheritance_mapping.xml:327#, no-c-formatmsgid "<one-to-many>"msgstr ""#. Tag: literal#: inheritance_mapping.xml:317 inheritance_mapping.xml:328 inheritance_mapping.xml:339#, no-c-formatmsgid "<many-to-many>"msgstr ""#. Tag: literal#: inheritance_mapping.xml:318 inheritance_mapping.xml:329 inheritance_mapping.xml:340#, no-c-formatmsgid "s.get(Payment.class, id)"msgstr ""#. Tag: literal#: inheritance_mapping.xml:319 inheritance_mapping.xml:330 inheritance_mapping.xml:341 inheritance_mapping.xml:352#, no-c-formatmsgid "from Payment p"msgstr ""#. Tag: literal#: inheritance_mapping.xml:320 inheritance_mapping.xml:331 inheritance_mapping.xml:342#, no-c-formatmsgid "from Order o join o.payment p"msgstr ""#. Tag: emphasis#: inheritance_mapping.xml:321 inheritance_mapping.xml:332 inheritance_mapping.xml:343#, no-c-formatmsgid "supported"msgstr ""#. Tag: entry#: inheritance_mapping.xml:324#, no-c-formatmsgid "<entry>table per subclass</entry>"msgstr ""#. Tag: entry#: inheritance_mapping.xml:335#, no-c-formatmsgid "table per concrete-class (union-subclass)"msgstr ""#. Tag: entry#: inheritance_mapping.xml:338#, no-c-formatmsgid "<literal><one-to-many></literal> (for <literal>inverse=\"true\"</literal> only)"msgstr ""#. Tag: entry#: inheritance_mapping.xml:346#, no-c-formatmsgid "table per concrete class (implicit polymorphism)"msgstr ""#. Tag: literal#: inheritance_mapping.xml:347#, no-c-formatmsgid "<any>"msgstr ""#. Tag: emphasis#: inheritance_mapping.xml:348 inheritance_mapping.xml:349 inheritance_mapping.xml:353 inheritance_mapping.xml:354#, no-c-formatmsgid "not supported"msgstr ""#. Tag: literal#: inheritance_mapping.xml:350#, no-c-formatmsgid "<many-to-any>"msgstr ""#. Tag: literal#: inheritance_mapping.xml:351#, no-c-formatmsgid "s.createCriteria(Payment.class).add( Restrictions.idEq(id) ).uniqueResult()"msgstr ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -