📄 persistent_classes.pot
字号:
msgstr ""#. Tag: para#: persistent_classes.xml:188#, no-c-formatmsgid "intend to use reattachment of detached instances"msgstr ""#. Tag: para#: persistent_classes.xml:194#, no-c-formatmsgid "Hibernate guarantees equivalence of persistent identity (database row) and Java identity only inside a particular session scope. So as soon as we mix instances retrieved in different sessions, we must implement <literal>equals()</literal> and <literal>hashCode()</literal> if we wish to have meaningful semantics for <literal>Set</literal>s."msgstr ""#. Tag: para#: persistent_classes.xml:202#, no-c-formatmsgid "The most obvious way is to implement <literal>equals()</literal>/<literal>hashCode()</literal> by comparing the identifier value of both objects. If the value is the same, both must be the same database row, they are therefore equal (if both are added to a <literal>Set</literal>, we will only have one element in the <literal>Set</literal>). Unfortunately, we can't use that approach with generated identifiers! Hibernate will only assign identifier values to objects that are persistent, a newly created instance will not have any identifier value! Furthermore, if an instance is unsaved and currently in a <literal>Set</literal>, saving it will assign an identifier value to the object. If <literal>equals()</literal> and <literal>hashCode()</literal> are based on the identifier value, the hash code would change, breaking the contract of the <literal>Set</literal>. See the Hibernate website for a full discussion of this problem. Note that this is not a Hibernate issue, but normal Java semantics of object identity and equality."msgstr ""#. Tag: para#: persistent_classes.xml:216#, no-c-formatmsgid "We recommend implementing <literal>equals()</literal> and <literal>hashCode()</literal> using <emphasis>Business key equality</emphasis>. Business key equality means that the <literal>equals()</literal> method compares only the properties that form the business key, a key that would identify our instance in the real world (a <emphasis>natural</emphasis> candidate key):"msgstr ""#. Tag: programlisting#: persistent_classes.xml:224#, no-c-formatmsgid "" "<![CDATA[public class Cat {\n" "\n" " ...\n" " public boolean equals(Object other) {\n" " if (this == other) return true;\n" " if ( !(other instanceof Cat) ) return false;\n" "\n" " final Cat cat = (Cat) other;\n" "\n" " if ( !cat.getLitterId().equals( getLitterId() ) ) return false;\n" " if ( !cat.getMother().equals( getMother() ) ) return false;\n" "\n" " return true;\n" " }\n" "\n" " public int hashCode() {\n" " int result;\n" " result = getMother().hashCode();\n" " result = 29 * result + getLitterId();\n" " return result;\n" " }\n" "\n" "}]]>"msgstr ""#. Tag: para#: persistent_classes.xml:226#, no-c-formatmsgid "Note that a business key does not have to be as solid as a database primary key candidate (see <xref linkend=\"transactions-basics-identity\"/>). Immutable or unique properties are usually good candidates for a business key."msgstr ""#. Tag: title#: persistent_classes.xml:236#, no-c-formatmsgid "Dynamic models"msgstr ""#. Tag: emphasis#: persistent_classes.xml:239#, no-c-formatmsgid "Note that the following features are currently considered experimental and may change in the near future."msgstr ""#. Tag: para#: persistent_classes.xml:243#, no-c-formatmsgid "Persistent entities don't necessarily have to be represented as POJO classes or as JavaBean objects at runtime. Hibernate also supports dynamic models (using <literal>Map</literal>s of <literal>Map</literal>s at runtime) and the representation of entities as DOM4J trees. With this approach, you don't write persistent classes, only mapping files."msgstr ""#. Tag: para#: persistent_classes.xml:251#, no-c-formatmsgid "By default, Hibernate works in normal POJO mode. You may set a default entity representation mode for a particular <literal>SessionFactory</literal> using the <literal>default_entity_mode</literal> configuration option (see <xref linkend=\"configuration-optional-properties\"/>."msgstr ""#. Tag: para#: persistent_classes.xml:258#, no-c-formatmsgid "The following examples demonstrates the representation using <literal>Map</literal>s. First, in the mapping file, an <literal>entity-name</literal> has to be declared instead of (or in addition to) a class name:"msgstr ""#. Tag: programlisting#: persistent_classes.xml:264#, no-c-formatmsgid "" "<![CDATA[<hibernate-mapping>\n" "\n" " <class entity-name=\"Customer\">\n" "\n" " <id name=\"id\"\n" " type=\"long\"\n" " column=\"ID\">\n" " <generator class=\"sequence\"/>\n" " </id>\n" "\n" " <property name=\"name\"\n" " column=\"NAME\"\n" " type=\"string\"/>\n" "\n" " <property name=\"address\"\n" " column=\"ADDRESS\"\n" " type=\"string\"/>\n" "\n" " <many-to-one name=\"organization\"\n" " column=\"ORGANIZATION_ID\"\n" " class=\"Organization\"/>\n" "\n" " <bag name=\"orders\"\n" " inverse=\"true\"\n" " lazy=\"false\"\n" " cascade=\"all\">\n" " <key column=\"CUSTOMER_ID\"/>\n" " <one-to-many class=\"Order\"/>\n" " </bag>\n" "\n" " </class>\n" " \n" "</hibernate-mapping>]]>"msgstr ""#. Tag: para#: persistent_classes.xml:266#, no-c-formatmsgid "Note that even though associations are declared using target class names, the target type of an associations may also be a dynamic entity instead of a POJO."msgstr ""#. Tag: para#: persistent_classes.xml:273#, no-c-formatmsgid "After setting the default entity mode to <literal>dynamic-map</literal> for the <literal>SessionFactory</literal>, we can at runtime work with <literal>Map</literal>s of <literal>Map</literal>s:"msgstr ""#. Tag: programlisting#: persistent_classes.xml:279#, no-c-formatmsgid "" "<![CDATA[Session s = openSession();\n" "Transaction tx = s.beginTransaction();\n" "Session s = openSession();\n" "\n" "// Create a customer\n" "Map david = new HashMap();\n" "david.put(\"name\", \"David\");\n" "\n" "// Create an organization\n" "Map foobar = new HashMap();\n" "foobar.put(\"name\", \"Foobar Inc.\");\n" "\n" "// Link both\n" "david.put(\"organization\", foobar);\n" "\n" "// Save both\n" "s.save(\"Customer\", david);\n" "s.save(\"Organization\", foobar);\n" "\n" "tx.commit();\n" "s.close();]]>"msgstr ""#. Tag: para#: persistent_classes.xml:281#, no-c-formatmsgid "The advantages of a dynamic mapping are quick turnaround time for prototyping without the need for entity class implementation. However, you lose compile-time type checking and will very likely deal with many exceptions at runtime. Thanks to the Hibernate mapping, the database schema can easily be normalized and sound, allowing to add a proper domain model implementation on top later on."msgstr ""#. Tag: para#: persistent_classes.xml:289#, no-c-formatmsgid "Entity representation modes can also be set on a per <literal>Session</literal> basis:"msgstr ""#. Tag: programlisting#: persistent_classes.xml:294#, no-c-formatmsgid "" "<![CDATA[Session dynamicSession = pojoSession.getSession(EntityMode.MAP);\n" "\n" "// Create a customer\n" "Map david = new HashMap();\n" "david.put(\"name\", \"David\");\n" "dynamicSession.save(\"Customer\", david);\n" "...\n" "dynamicSession.flush();\n" "dynamicSession.close()\n" "...\n" "// Continue on pojoSession\n" "]]>"msgstr ""#. Tag: para#: persistent_classes.xml:297#, no-c-formatmsgid "Please note that the call to <literal>getSession()</literal> using an <literal>EntityMode</literal> is on the <literal>Session</literal> API, not the <literal>SessionFactory</literal>. That way, the new <literal>Session</literal> shares the underlying JDBC connection, transaction, and other context information. This means you don't have tocall <literal>flush()</literal> and <literal>close()</literal> on the secondary <literal>Session</literal>, and also leave the transaction and connection handling to the primary unit of work."msgstr ""#. Tag: para#: persistent_classes.xml:307#, no-c-formatmsgid "More information about the XML representation capabilities can be found in <xref linkend=\"xml\"/>."msgstr ""#. Tag: title#: persistent_classes.xml:315#, no-c-formatmsgid "Tuplizers"msgstr ""#. Tag: para#: persistent_classes.xml:317#, no-c-formatmsgid "<literal>org.hibernate.tuple.Tuplizer</literal>, and its sub-interfaces, are responsible for managing a particular representation of a piece of data, given that representation's <literal>org.hibernate.EntityMode</literal>. If a given piece of data is thought of as a data structure, then a tuplizer is the thing which knows how to create such a data structure and how to extract values from and inject values into such a data structure. For example, for the POJO entity mode, the correpsonding tuplizer knows how create the POJO through its constructor and how to access the POJO properties using the defined property accessors. There are two high-level types of Tuplizers, represented by the <literal>org.hibernate.tuple.entity.EntityTuplizer</literal> and <literal>org.hibernate.tuple.component.ComponentTuplizer</literal> interfaces. <literal>EntityTuplizer</literal>s are responsible for managing the above mentioned contracts in regards to entities, while <literal>ComponentTuplizer</literal>s do the same for components."msgstr ""#. Tag: para#: persistent_classes.xml:332#, no-c-formatmsgid "Users may also plug in their own tuplizers. Perhaps you require that a <literal>java.util.Map</literal> implementation other than <literal>java.util.HashMap</literal> be used while in the dynamic-map entity-mode; or perhaps you need to define a different proxy generation strategy than the one used by default. Both would be achieved by defining a custom tuplizer implementation. Tuplizers definitions are attached to the entity or component mapping they are meant to manage. Going back to the example of our customer entity:"msgstr ""#. Tag: programlisting#: persistent_classes.xml:341#, no-c-formatmsgid "" "<![CDATA[<hibernate-mapping>\n" " <class entity-name=\"Customer\">\n" " <!--\n" " Override the dynamic-map entity-mode\n" " tuplizer for the customer entity\n" " -->\n" " <tuplizer entity-mode=\"dynamic-map\"\n" " class=\"CustomMapTuplizerImpl\"/>\n" "\n" " <id name=\"id\" type=\"long\" column=\"ID\">\n" " <generator class=\"sequence\"/>\n" " </id>\n" "\n" " <!-- other properties -->\n" " ...\n" " </class>\n" "</hibernate-mapping>\n" "\n" "\n" "public class CustomMapTuplizerImpl\n" " extends org.hibernate.tuple.entity.DynamicMapEntityTuplizer {\n" " // override the buildInstantiator() method to plug in our custom map...\n" " protected final Instantiator buildInstantiator(\n" " org.hibernate.mapping.PersistentClass mappingInfo) {\n" " return new CustomMapInstantiator( mappingInfo );\n" " }\n" "\n" " private static final class CustomMapInstantiator\n" " extends org.hibernate.tuple.DynamicMapInstantitor {\n" " // override the generateMap() method to return our custom map...\n" " protected final Map generateMap() {\n" " return new CustomMap();\n" " }\n" " }\n" "}]]>"msgstr ""#. Tag: title#: persistent_classes.xml:347#, no-c-formatmsgid "Extentsions"msgstr ""#. Tag: para#: persistent_classes.xml:348#, no-c-formatmsgid "TODO: Document user-extension framework in the property and proxy packages"msgstr ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -