📄 persistent_classes.po
字号:
"association fetching - which will limit your options for performance tuning."msgstr """你可以用Hibernate持久化一个没有实现任何接口的<literal>final</literal>类,但是""你 不能使用代理来延迟关联加载,这会限制你进行性能优化的选择。"#. Tag: para#: persistent_classes.xml:107#, no-c-formatmsgid """You should also avoid declaring <literal>public final</literal> methods on ""the non-final classes. If you want to use a class with a <literal>public ""final</literal> method, you must explicitly disable proxying by setting ""<literal>lazy=\"false\"</literal>."msgstr """你也应该避免在非final类中声明 <literal>public final</literal>的方法。如果你想""使用一 个有<literal>public final</literal>方法的类,你必须通过设置""<literal>lazy=\"false\"</literal> 来明确地禁用代理。"#. Tag: title#: persistent_classes.xml:115#, no-c-formatmsgid "Declare accessors and mutators for persistent fields (optional)"msgstr "为持久化字段声明访问器(accessors)和是否可变的标志(mutators)(可选)"#. Tag: para#: persistent_classes.xml:117#, no-c-formatmsgid """<literal>Cat</literal> declares accessor methods for all its persistent ""fields. Many other ORM tools directly persist instance variables. We believe ""it is better to provide an indirection between the relational schema and ""internal data structures of the class. By default, Hibernate persists ""JavaBeans style properties, and recognizes method names of the form ""<literal>getFoo</literal>, <literal>isFoo</literal> and <literal>setFoo</""literal>. You may switch to direct field access for particular properties, ""if needed."msgstr """<literal>Cat</literal>为它的所有持久化字段声明了访问方法。很多其他ORM工具直接""对 实例变量进行持久化。我们相信,在关系数据库schema和类的内部数据结构之间引入""间接层(原文为\"非直接\",indirection)会好一些。默认情况下Hibernate持久化""JavaBeans风格的属性,认可 <literal>getFoo</literal>,<literal>isFoo</""literal> 和 <literal>setFoo</literal>这种形式的方法名。 如果需要,你可以对某""些特定属性实行直接字段访问。"#. Tag: para#: persistent_classes.xml:127#, no-c-formatmsgid """Properties need <emphasis>not</emphasis> be declared public - Hibernate can ""persist a property with a default, <literal>protected</literal> or ""<literal>private</literal> get / set pair."msgstr """属性<emphasis>不需要</emphasis>要声明为public的。Hibernate可以持久化一个有 ""<literal>default</literal>、<literal>protected</literal>或<literal>private</""literal>的get/set方法对 的属性进行持久化。"#. Tag: title#: persistent_classes.xml:138#, no-c-formatmsgid "Implementing inheritance"msgstr "实现继承(Inheritance)"#. Tag: para#: persistent_classes.xml:140#, no-c-formatmsgid """A subclass must also observe the first and second rules. It inherits its ""identifier property from the superclass, <literal>Cat</literal>."msgstr """子类也必须遵守第一条和第二条规则。它从超类<literal>Cat</literal>继承了标识属""性。"#. Tag: programlisting#: persistent_classes.xml:145#, no-c-formatmsgid """<![CDATA[package eg;\n""\n""public class DomesticCat extends Cat {\n"" private String name;\n""\n"" public String getName() {\n"" return name;\n"" }\n"" protected void setName(String name) {\n"" this.name=name;\n"" }\n""}]]>"msgstr ""#. Tag: title#: persistent_classes.xml:149#, no-c-formatmsgid """Implementing <literal>equals()</literal> and <literal>hashCode()</literal>"msgstr "实现<literal>equals()</literal>和<literal>hashCode()</literal>"#. Tag: para#: persistent_classes.xml:151#, no-c-formatmsgid """You have to override the <literal>equals()</literal> and <literal>hashCode()""</literal> methods if you"msgstr """如果你有如下需求,你必须重载 <literal>equals()</literal> 和 <literal>hashCode""()</literal>方法:"#. Tag: para#: persistent_classes.xml:157#, no-c-formatmsgid """intend to put instances of persistent classes in a <literal>Set</literal> ""(the recommended way to represent many-valued associations) <emphasis>and</""emphasis>"msgstr """想把持久类的实例放入<literal>Set</literal>中(当表示多值关联时,推荐这么做)"#. Tag: para#: persistent_classes.xml:164#, no-c-formatmsgid "intend to use reattachment of detached instances"msgstr "想重用脱管实例"#. Tag: para#: persistent_classes.xml:170#, 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 """Hibernate保证,仅在特定会话范围内,持久化标识(数据库的行)和Java标识是等价""的。因此,一旦 我们混合了从不同会话中获取的实例,如果希望<literal>Set</""literal>有明确的语义,就必 须实现<literal>equals()</literal> 和""<literal>hashCode()</literal>。"#. Tag: para#: persistent_classes.xml:178#, 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 """实现<literal>equals()</literal>/<literal>hashCode()</literal>最显而易见的方法""是比较两个对象 标识符的值。如果值相同,则两个对象对应于数据库的同一行,因此它""们是相等的(如果都被添加到 <literal>Set</literal>,则在<literal>Set</literal>""中只有一个元素)。不幸的是,对生成的标识不能 使用这种方法。Hibernate仅对那些""持久化对象赋标识值,一个新创建的实例将不会有任何标识值。此外, 如果一个实例没""有被保存(unsaved),并且它当前正在一个<literal>Set</literal>中,保存它将会给这""个对象 赋一个标识值。如果<literal>equals()</literal> 和 <literal>hashCode()</""literal>是基于标识值 实现的,则其哈希码将会改变,这违反了<literal>Set</""literal>的契约。建议去Hibernate的站点阅读关于这个 问题的全部讨论。注意,这不""是Hibernate的问题,而是一般的Java对象标识和Java对象等价的语义问题。"#. Tag: para#: persistent_classes.xml:192#, 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 """我们建议使用<emphasis>业务键值相等(Business key equality)</emphasis>来实现""<literal>equals()</literal> 和 <literal>hashCode()</literal>。业务键值相等的""意思是,<literal>equals()</literal>方法 仅仅比较形成业务键的属性,它能在现实""世界里标识我们的实例(是一个<emphasis>自然的</emphasis>候选码)。"#. Tag: programlisting#: persistent_classes.xml:200#, 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:202#, 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 """注意,业务键不必像数据库的主键那样固定不变(参见<xref linkend=\"transactions-""basics-identity\"/>)。 对业务键而言,不可变或唯一的属性是不错的选择。"#. Tag: title#: persistent_classes.xml:212#, no-c-formatmsgid "Dynamic models"msgstr "动态模型(Dynamic models)"#. Tag: emphasis#: persistent_classes.xml:215#, 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:219#, 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 """运行期的持久化实体没有必要一定表示为像POJO类或JavaBean对象那样的形式。""Hibernate也支持动态模型 (在运行期使用<literal>Map</literal>的<literal>Map</""literal>)和象DOM4J的树模型那 样的实体表示。使用这种方法,你不用写持久化类,""只写映射文件就行了。"#. Tag: para#: persistent_classes.xml:227#, 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 """Hibernate默认工作在普通POJO模式。你可以使用配置选项""<literal>default_entity_mode</literal>, 对特定的<literal>SessionFactory</""literal>,设置一个默认的实体表示模式。 (参见<xref linkend=\"configuration-""optional-properties\"/>。)"#. Tag: para#: persistent_classes.xml:234
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -