|
Hibernate example source code file (persistent_classes.po)
This example Hibernate source code file (persistent_classes.po) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Hibernate persistent_classes.po source code
# translation of persistent_classes.po to
# Xi Huang <xhuang@redhat.com>, 2006.
# Xi HUANG <xhuang@redhat.com>, 2007, 2009.
# translation of Collection_Mapping.po to
msgid ""
msgstr ""
"Project-Id-Version: persistent_classes\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-20 21:02+0000\n"
"PO-Revision-Date: 2010-03-16 10:00+1000\n"
"Last-Translator: Xi HUANG <xhuang@redhat.com>\n"
"Language-Team: <en@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: KBabel 1.11.4\n"
#. Tag: title
#: persistent_classes.xml:32
#, no-c-format
msgid "Persistent Classes"
msgstr "æŒä¹…化类(Persistent Classes)"
#. Tag: para
#: persistent_classes.xml:34
#, fuzzy, no-c-format
msgid ""
"Persistent classes are classes in an application that implement the entities "
"of the business problem (e.g. Customer and Order in an E-commerce "
"application). The term \"persistent\" here means that the classes are able "
"to be persisted, not that they are in the persistent state (see <xref "
"linkend=\"objectstate-overview\"/> for discussion)."
msgstr ""
"在应用程åºä¸ï¼Œç”¨æ¥å®žçŽ°ä¸šåŠ¡é—®é¢˜å®žä½“的(如,在电å商务应用程åºä¸çš„ Customer å’Œ "
"Order)类就是æŒä¹…化类。ä¸èƒ½è®¤ä¸ºæ‰€æœ‰çš„æŒä¹…化类的实例都是æŒä¹…çš„çŠ¶æ€ - 一个实例"
"的状æ€ä¹Ÿå¯èƒ½æ˜¯çž¬æ—¶çš„或脱管的。"
#. Tag: para
#: persistent_classes.xml:41
#, fuzzy, no-c-format
msgid ""
"Hibernate works best if these classes follow some simple rules, also known "
"as the Plain Old Java Object (POJO) programming model. However, none of "
"these rules are hard requirements. Indeed, Hibernate assumes very little "
"about the nature of your persistent objects. You can express a domain model "
"in other ways (using trees of <interfacename>java.util.Map "
"instances, for example)."
msgstr ""
"如果这些æŒä¹…化类éµå¾ªä¸€äº›ç®€å•çš„规则,Hibernate 能够工作得更好,这些规则也被称"
"作简å•ä¼ 统 Java 对象(POJO:Plain Old Java Object)编程模型。但是这些规则并ä¸"
"是必需的。 实际上,Hibernate3 å¯¹äºŽä½ çš„æŒä¹…åŒ–ç±»å‡ ä¹Žä¸åšä»»ä½•è®¾æƒ³ã€‚ä½ å¯ä»¥ç”¨å…¶ä»–"
"的方法æ¥è¡¨è¾¾é¢†åŸŸæ¨¡åž‹ï¼šæ¯”如,使用 <literal>Map å®žä¾‹çš„æ ‘åž‹ç»“æž„ã€‚"
#. Tag: title
#: persistent_classes.xml:49
#, no-c-format
msgid "A simple POJO example"
msgstr "一个简å•çš„ POJO 例å"
#. Tag: title
#: persistent_classes.xml:52
#, no-c-format
msgid "Simple POJO representing a cat"
msgstr ""
#. Tag: programlisting
#: persistent_classes.xml:53
#, fuzzy, no-c-format
msgid ""
"package eg;\n"
"import java.util.Set;\n"
"import java.util.Date;\n"
"\n"
"public class Cat {\n"
"private Long id; // identifier\n"
"\n"
"private Date birthdate;\n"
"private Color color;\n"
"private char sex;\n"
"private float weight;\n"
" private int litterId;\n"
"\n"
" private Cat mother;\n"
" private Set kittens = new HashSet();\n"
"\n"
" private void setId(Long id) {\n"
" this.id=id;\n"
" }\n"
" public Long getId() {\n"
" return id;\n"
" }\n"
"\n"
" void setBirthdate(Date date) {\n"
" birthdate = date;\n"
" }\n"
" public Date getBirthdate() {\n"
" return birthdate;\n"
" }\n"
"\n"
" void setWeight(float weight) {\n"
" this.weight = weight;\n"
" }\n"
" public float getWeight() {\n"
" return weight;\n"
" }\n"
"\n"
" public Color getColor() {\n"
" return color;\n"
" }\n"
" void setColor(Color color) {\n"
" this.color = color;\n"
" }\n"
"\n"
" void setSex(char sex) {\n"
" this.sex=sex;\n"
" }\n"
" public char getSex() {\n"
" return sex;\n"
" }\n"
"\n"
" void setLitterId(int id) {\n"
" this.litterId = id;\n"
" }\n"
" public int getLitterId() {\n"
" return litterId;\n"
" }\n"
"\n"
" void setMother(Cat mother) {\n"
" this.mother = mother;\n"
" }\n"
" public Cat getMother() {\n"
" return mother;\n"
" }\n"
" void setKittens(Set kittens) {\n"
" this.kittens = kittens;\n"
" }\n"
" public Set getKittens() {\n"
" return kittens;\n"
" }\n"
"\n"
" // addKitten not needed by Hibernate\n"
" public void addKitten(Cat kitten) {\n"
" kitten.setMother(this);\n"
" kitten.setLitterId( kittens.size() );\n"
" kittens.add(kitten);\n"
" }\n"
"}"
msgstr ""
"<![CDATA[package eg;\n"
"import java.util.Set;\n"
"import java.util.Date;\n"
"\n"
"public class Cat {\n"
" private Long id; // identifier\n"
"\n"
" private Date birthdate;\n"
" private Color color;\n"
" private char sex;\n"
" private float weight;\n"
" private int litterId;\n"
"\n"
" private Cat mother;\n"
" private Set kittens = new HashSet();\n"
"\n"
" private void setId(Long id) {\n"
" this.id=id;\n"
" }\n"
" public Long getId() {\n"
" return id;\n"
" }\n"
"\n"
" void setBirthdate(Date date) {\n"
" birthdate = date;\n"
" }\n"
" public Date getBirthdate() {\n"
" return birthdate;\n"
" }\n"
"\n"
" void setWeight(float weight) {\n"
" this.weight = weight;\n"
" }\n"
" public float getWeight() {\n"
" return weight;\n"
" }\n"
"\n"
" public Color getColor() {\n"
" return color;\n"
" }\n"
" void setColor(Color color) {\n"
" this.color = color;\n"
" }\n"
"\n"
" void setSex(char sex) {\n"
" this.sex=sex;\n"
" }\n"
" public char getSex() {\n"
" return sex;\n"
" }\n"
"\n"
" void setLitterId(int id) {\n"
" this.litterId = id;\n"
" }\n"
" public int getLitterId() {\n"
" return litterId;\n"
" }\n"
"\n"
" void setMother(Cat mother) {\n"
" this.mother = mother;\n"
" }\n"
" public Cat getMother() {\n"
" return mother;\n"
" }\n"
" void setKittens(Set kittens) {\n"
" this.kittens = kittens;\n"
" }\n"
" public Set getKittens() {\n"
" return kittens;\n"
" }\n"
" \n"
" // addKitten not needed by Hibernate\n"
" public void addKitten(Cat kitten) {\n"
" kitten.setMother(this);\n"
" kitten.setLitterId( kittens.size() ); \n"
" kittens.add(kitten);\n"
" }\n"
"}]]>"
#. Tag: para
#: persistent_classes.xml:57
#, no-c-format
msgid ""
"The four main rules of persistent classes are explored in more detail in the "
"following sections."
msgstr "在åŽç»çš„ç« èŠ‚é‡Œæˆ‘ä»¬å°†ä»‹ç»æŒä¹…性类的 4 个主è¦è§„则的更多细节。"
#. Tag: title
#: persistent_classes.xml:62
#, no-c-format
msgid "Implement a no-argument constructor"
msgstr "实现一个默认的(å³æ— å‚æ•°çš„ï¼‰æž„é€ æ–¹æ³•ï¼ˆconstructor)"
#. Tag: para
#: persistent_classes.xml:64
#, fuzzy, no-c-format
msgid ""
"<classname>Cat has a no-argument constructor. All persistent "
"classes must have a default constructor (which can be non-public) so that "
"Hibernate can instantiate them using <literal>java.lang.reflect."
"Constructor</classname>.newInstance(). It is recommended that this "
"constructor be defined with at least <emphasis>package visibility "
"in order for runtime proxy generation to work properly."
msgstr ""
"<literal>Cat æœ‰ä¸€ä¸ªæ— å‚æ•°çš„æž„é€ æ–¹æ³•ã€‚æ‰€æœ‰çš„æŒä¹…化类都必须有一个默认"
"çš„æž„é€ æ–¹æ³•ï¼ˆå¯ä»¥ä¸æ˜¯ public çš„ï¼‰ï¼Œè¿™æ ·çš„è¯ Hibernate å°±å¯ä»¥ä½¿ç”¨ "
"<literal>Constructor.newInstance()æ¥å®žä¾‹åŒ–它们。 我们强烈建议,在 "
"Hibernate ä¸ï¼Œä¸ºäº†è¿è¡ŒæœŸä»£ç†çš„生æˆï¼Œæž„é€ æ–¹æ³•è‡³å°‘æ˜¯<emphasis>包(package) has a property named id. This "
"property maps to the primary key column(s) of the underlying database table. "
"The type of the identifier property can be any \"basic\" type (see <xref "
"linkend=\"types.value.basic\"/>). See <xref linkend=\"components-compositeid"
"\"/> for information on mapping composite (multi-column) identifiers."
msgstr ""
#. Tag: para
#: persistent_classes.xml:92
#, no-c-format
msgid ""
"Identifiers do not necessarily need to identify column(s) in the database "
"physically defined as a primary key. They should just identify columns that "
"can be used to uniquely identify rows in the underlying table."
msgstr ""
#. Tag: para
#: persistent_classes.xml:99
#, no-c-format
msgid ""
"We recommend that you declare consistently-named identifier properties on "
"persistent classes and that you use a nullable (i.e., non-primitive) type."
msgstr ""
"æˆ‘ä»¬å»ºè®®ä½ å¯¹æŒä¹…化类声明命åä¸€è‡´çš„æ ‡è¯†å±žæ€§ã€‚æˆ‘ä»¬è¿˜å»ºè®®ä½ ä½¿ç”¨ä¸€ä¸ªå¯ä»¥ä¸ºç©ºï¼ˆä¹Ÿ"
"就是说,ä¸æ˜¯åŽŸå§‹ç±»åž‹ï¼‰çš„类型。 "
#. Tag: title
#: persistent_classes.xml:107
#, fuzzy, no-c-format
msgid "Prefer non-final classes (semi-optional)"
msgstr "使用éžfinal的类(å¯é€‰ï¼‰"
#. Tag: para
#: persistent_classes.xml:109
#, no-c-format
msgid ""
"A central feature of Hibernate, <emphasis>proxies (lazy loading), "
"depends upon the persistent class being either non-final, or the "
"implementation of an interface that declares all public methods. You can "
"persist <literal>final classes that do not implement an interface "
"with Hibernate; you will not, however, be able to use proxies for lazy "
"association fetching which will ultimately limit your options for "
"performance tuning. To persist a <literal>final class which does "
"not implement a \"full\" interface you must disable proxy generation. See "
"<xref linkend=\"persistent-classes-pojo-final-example-disable-proxies-xml\"/"
"> and <xref linkend=\"persistent-classes-pojo-final-example-disable-proxies-"
"ann\"/>."
msgstr ""
#. Tag: title
#: persistent_classes.xml:121
#, no-c-format
msgid "Disabling proxies in <literal>hbm.xml"
msgstr ""
#. Tag: programlisting
#: persistent_classes.xml:122
#, no-c-format
msgid "<![CDATA[]]>"
msgstr ""
#. Tag: title
#: persistent_classes.xml:126
#, no-c-format
msgid "Disabling proxies in annotations"
msgstr ""
#. Tag: programlisting
#: persistent_classes.xml:127
#, no-c-format
msgid "<![CDATA[@Entity @Proxy(lazy=false) public class Cat { ... }]]>"
msgstr ""
#. Tag: para
#: persistent_classes.xml:130
#, no-c-format
msgid ""
"If the <literal>final class does implement a proper interface, you "
"could alternatively tell Hibernate to use the interface instead when "
"generating the proxies. See <xref linkend=\"persistent-classes-pojo-final-"
"example-proxy-interface-xml\"/> and <xref linkend=\"persistent-classes-pojo-"
"final-example-proxy-interface-ann\"/>."
msgstr ""
#. Tag: title
#: persistent_classes.xml:139
#, no-c-format
msgid "Proxying an interface in <literal>hbm.xml"
msgstr ""
#. Tag: programlisting
#: persistent_classes.xml:140
#, no-c-format
msgid "<![CDATA[]]>"
msgstr ""
#. Tag: title
#: persistent_classes.xml:144
#, no-c-format
msgid "Proxying an interface in annotations"
msgstr ""
#. Tag: programlisting
#: persistent_classes.xml:145
#, no-c-format
msgid ""
"<![CDATA[@Entity @Proxy(proxyClass=ICat.class) public class Cat implements "
"ICat { ... }]]>"
msgstr ""
#. Tag: para
#: persistent_classes.xml:148
#, fuzzy, no-c-format
msgid ""
"You should also avoid declaring <literal>public final methods as "
"this will again limit the ability to generate <emphasis>proxies "
"from this class. If you want to use a class with <literal>public final 的方法。如果"
"ä½ æƒ³ä½¿ç”¨ä¸€ä¸ªæœ‰ <literal>public final æ–¹æ³•çš„ç±»ï¼Œä½ å¿…é¡»é€šè¿‡è®¾ç½® "
"<literal>lazy=\"false\" æ¥æ˜Žç¡®åœ°ç¦ç”¨ä»£ç†ã€‚ "
#. Tag: title
#: persistent_classes.xml:158
#, no-c-format
msgid "Declare accessors and mutators for persistent fields (optional)"
msgstr ""
"为æŒä¹…化å—段声明访问器(accessors)和是å¦å¯å˜çš„æ ‡å¿—ï¼ˆmutators)(å¯é€‰ï¼‰"
#. Tag: para
#: persistent_classes.xml:160
#, fuzzy, no-c-format
msgid ""
"<classname>Cat declares accessor methods for all its persistent "
"fields. Many other ORM tools directly persist instance variables. 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>getFooisFoo and setFoo. If "
"required, you can switch to direct field access for particular properties."
msgstr ""
"<literal>Cat 为它的所有æŒä¹…化å—段声明了访问方法。很多其他 ORM 工具"
"直接对实例å˜é‡è¿›è¡ŒæŒä¹…化。我们相信,在关系数æ®åº“ schema 和类的内部数æ®ç»“构之"
"间引入间接层(原文为\"éžç›´æŽ¥\",indirection)会好一些。默认情况下 Hibernate "
"æŒä¹…化 JavaBeans é£Žæ ¼çš„å±žæ€§ï¼Œè®¤å¯ <literal>getFoo,"
"<literal>isFoo å’Œ setFoo è¿™ç§å½¢å¼çš„方法å。如果"
"需è¦ï¼Œä½ å¯ä»¥å¯¹æŸäº›ç‰¹å®šå±žæ€§å®žè¡Œç›´æŽ¥å—段访问。 "
#. Tag: para
#: persistent_classes.xml:169
#, fuzzy, no-c-format
msgid ""
"Properties need <emphasis>not be declared public. Hibernate can "
"persist a property declared with <literal>package, "
"<literal>protected or private visibility as "
"well."
msgstr ""
"属性<emphasis>ä¸éœ€è¦è¦å£°æ˜Žä¸º public 的。Hibernate å¯ä»¥æŒä¹…化一个"
"有 <literal>defaultã€protected 或 "
"<literal>private çš„ get/set 方法对的属性进行æŒä¹…化。"
#. Tag: title
#: persistent_classes.xml:178
#, no-c-format
msgid "Implementing inheritance"
msgstr "实现继承(Inheritance)"
#. Tag: para
#: persistent_classes.xml:180
#, no-c-format
msgid ""
"A subclass must also observe the first and second rules. It inherits its "
"identifier property from the superclass, <literal>Cat. For example:"
msgstr ""
"å类也必须éµå®ˆç¬¬ä¸€æ¡å’Œç¬¬äºŒæ¡è§„则。它从超类 <literal>Cat ç»§æ‰¿äº†æ ‡è¯†"
"属性。例如:"
#. Tag: programlisting
#: persistent_classes.xml:184
#, fuzzy, no-c-format
msgid ""
"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 ""
"<![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"
"}]]>"
#. Tag: title
#: persistent_classes.xml:188
#, no-c-format
msgid ""
"Implementing <literal>equals() and hashCode()"
msgstr ""
"实现 <literal>equals() 和 hashCode() 方法:"
#. Tag: para
#: persistent_classes.xml:191
#, no-c-format
msgid ""
"You have to override the <literal>equals() and hashCode()"
"</literal> methods if you:"
msgstr ""
"å¦‚æžœä½ æœ‰å¦‚ä¸‹éœ€æ±‚ï¼Œä½ å¿…é¡»é‡è½½ <literal>equals() å’Œ hashCode"
"()</literal> 方法: "
#. Tag: para
#: persistent_classes.xml:196
#, no-c-format
msgid ""
"intend to put instances of persistent classes in a <literal>Set "
"(the recommended way to represent many-valued associations); <emphasis>and ä¸ï¼ˆå½“表示多值关è”时,推è这么"
"åšï¼‰ï¼Œ<emphasis>而且"
#. Tag: para
#: persistent_classes.xml:202
#, no-c-format
msgid "intend to use reattachment of detached instances"
msgstr "想é‡ç”¨è„±ç®¡å®žä¾‹"
#. Tag: para
#: persistent_classes.xml:206
#, no-c-format
msgid ""
"Hibernate guarantees equivalence of persistent identity (database row) and "
"Java identity only inside a particular session scope. When you mix instances "
"retrieved in different sessions, you must implement <literal>equals()hashCode() if you wish to have meaningful "
"semantics for <literal>Sets."
msgstr ""
"Hibernate ä¿è¯ï¼Œä»…在特定会è¯èŒƒå›´å†…,æŒä¹…åŒ–æ ‡è¯†ï¼ˆæ•°æ®åº“的行)和 Java æ ‡è¯†æ˜¯ç‰"
"ä»·çš„ã€‚å› æ¤ï¼Œä¸€æ—¦æˆ‘们混åˆäº†ä»Žä¸åŒä¼šè¯ä¸èŽ·å–的实例,如果希望 <literal>Setequals() å’Œ "
"<literal>hashCode()。 "
#. Tag: para
#: persistent_classes.xml:212
#, no-c-format
msgid ""
"The most obvious way is to implement <literal>equals()/"
"<literal>hashCode() by comparing the identifier value of both "
"objects. If the value is the same, both must be the same database row, "
"because they are equal. If both are added to a <literal>Set, you "
"will only have one element in the <literal>Set). Unfortunately, "
"you cannot 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, saving it will assign an "
"identifier value to the object. If <literal>equals() and "
"<literal>hashCode() are based on the identifier value, the hash "
"code would change, breaking the contract of the <literal>Set. See "
"the Hibernate website for a full discussion of this problem. This is not a "
"Hibernate issue, but normal Java semantics of object identity and equality."
msgstr ""
"实现 <literal>equals()/hashCode() 最显而易è§çš„æ–¹"
"法是比较两个对象 æ ‡è¯†ç¬¦çš„å€¼ã€‚å¦‚æžœå€¼ç›¸åŒï¼Œåˆ™ä¸¤ä¸ªå¯¹è±¡å¯¹åº”于数æ®åº“çš„åŒä¸€è¡Œï¼Œå› æ¤"
"它们是相ç‰çš„ï¼ˆå¦‚æžœéƒ½è¢«æ·»åŠ åˆ° <literal>Set,则在 Setequals()hashCode() æ˜¯åŸºäºŽæ ‡è¯†å€¼ 实现的,则其哈希ç 将会"
"改å˜ï¼Œè¿™è¿å了 <literal>Set 的契约。建议去 Hibernate 的站点阅读关于"
"这个问题的全部讨论。注æ„,这ä¸æ˜¯ Hibernate 的问题,而是一般的 Java å¯¹è±¡æ ‡è¯†"
"å’Œ Java 对象ç‰ä»·çš„è¯ä¹‰é—®é¢˜ã€‚ "
#. Tag: para
#: persistent_classes.xml:228
#, no-c-format
msgid ""
"It is recommended that you implement <literal>equals() and "
"<literal>hashCode() using Business key equalityequals() "
"method compares only the properties that form the business key. It is a key "
"that would identify our instance in the real world (a <emphasis>naturalæ¥å®žçŽ° "
"<literal>equals() å’Œ hashCode()。业务键值相ç‰çš„"
"æ„æ€æ˜¯ï¼Œ<literal>equals() 方法仅仅比较形æˆä¸šåŠ¡é”®çš„属性,它能在现实"
"ä¸–ç•Œé‡Œæ ‡è¯†æˆ‘ä»¬çš„å®žä¾‹ï¼ˆæ˜¯ä¸€ä¸ª<emphasis>自然的候选ç )。"
#. Tag: programlisting
#: persistent_classes.xml:235
#, fuzzy, no-c-format
msgid ""
"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 ""
"<![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"
"}]]>"
#. Tag: para
#: persistent_classes.xml:237
#, fuzzy, no-c-format
msgid ""
"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:244
#, no-c-format
msgid "Dynamic models"
msgstr "动æ€æ¨¡åž‹ï¼ˆDynamic models)"
#. Tag: title
#: persistent_classes.xml:247
#, no-c-format
msgid "Note"
msgstr "注æ„"
#. Tag: emphasis
#: persistent_classes.xml:249
#, fuzzy, no-c-format
msgid ""
"The following features are currently considered experimental and may change "
"in the near future."
msgstr ""
"<emphasis>注æ„,以下特性在当å‰å¤„于试验阶段,将æ¥å¯èƒ½ä¼šæœ‰å˜åŒ–。 "
#. Tag: para
#: persistent_classes.xml:253
#, no-c-format
msgid ""
"Persistent entities do not necessarily have to be represented as POJO "
"classes or as JavaBean objects at runtime. Hibernate also supports dynamic "
"models (using <literal>Maps of Maps at runtime) "
"and the representation of entities as DOM4J trees. With this approach, you "
"do not write persistent classes, only mapping files."
msgstr ""
"è¿è¡ŒæœŸçš„æŒä¹…化实体没有必è¦ä¸€å®šè¡¨ç¤ºä¸ºåƒ POJO 类或 JavaBean å¯¹è±¡é‚£æ ·çš„å½¢å¼ã€‚"
"Hibernate 也支æŒåŠ¨æ€æ¨¡åž‹ (在è¿è¡ŒæœŸä½¿ç”¨ <literal>Map çš„ "
"<literal>Map)和象 DOM4J çš„æ ‘æ¨¡åž‹é‚£æ ·çš„å®žä½“è¡¨ç¤ºã€‚ä½¿ç”¨è¿™ç§æ–¹æ³•ï¼Œä½ ä¸"
"用写æŒä¹…化类,åªå†™æ˜ 射文件就行了。 "
#. Tag: para
#: persistent_classes.xml:259
#, fuzzy, no-c-format
msgid ""
"By default, Hibernate works in normal POJO mode. You can set a default "
"entity representation mode for a particular <literal>SessionFactorydefault_entity_mode configuration "
"option (see <xref linkend=\"configuration-optional-properties\"/>)."
msgstr ""
"Hibernate 默认工作在普通 POJO 模å¼ã€‚ä½ å¯ä»¥ä½¿ç”¨é…置选项 "
"<literal>default_entity_mode, 对特定的 SessionFactoryentity-name has "
"to be declared instead of, or in addition to, a class name:"
msgstr ""
"下é¢æ˜¯ç”¨ <literal>Map æ¥è¡¨ç¤ºçš„例åã€‚é¦–å…ˆï¼Œåœ¨æ˜ å°„æ–‡ä»¶ä¸ï¼Œè¦å£°æ˜Ž "
"<literal>entity-name æ¥ä»£æ›¿ä¸€ä¸ªç±»å(或作为一ç§é™„属)。 "
#. Tag: programlisting
#: persistent_classes.xml:270
#, fuzzy, no-c-format
msgid ""
"<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 ""
"<![CDATA["
#. Tag: para
#: persistent_classes.xml:272
#, no-c-format
msgid ""
"Even though associations are declared using target class names, the target "
"type of associations can also be a dynamic entity instead of a POJO."
msgstr ""
"注æ„ï¼Œè™½ç„¶æ˜¯ç”¨ç›®æ ‡ç±»åæ¥å£°æ˜Žå…³è”的,但是关è”çš„ç›®æ ‡ç±»åž‹é™¤äº†æ˜¯ POJO 之外,也å¯"
"以是一个动æ€çš„实体。 "
#. Tag: para
#: persistent_classes.xml:276
#, no-c-format
msgid ""
"After setting the default entity mode to <literal>dynamic-map for "
"the <literal>SessionFactory, you can, at runtime, work with "
"<literal>Maps of Maps:"
msgstr ""
"在使用 <literal>dynamic-map 为 SessionFactory 设"
"置了默认的实体模å¼ä¹‹åŽï¼Œå¯ä»¥åœ¨è¿è¡ŒæœŸä½¿ç”¨ <literal>Map çš„ "
"<literal>Map:"
#. Tag: programlisting
#: persistent_classes.xml:281
#, fuzzy, no-c-format
msgid ""
"Session s = openSession();\n"
"Transaction tx = s.beginTransaction();\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 ""
"<![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();]]>"
#. Tag: para
#: persistent_classes.xml:283
#, no-c-format
msgid ""
"One of the main advantages of dynamic mapping is quick turnaround time for "
"prototyping, without the need for entity class implementation. However, you "
"lose compile-time type checking and will likely deal with many exceptions at "
"runtime. As a result of 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 ""
"动æ€æ˜ 射的好处是,å˜åŒ–所需è¦çš„æ—¶é—´å°‘äº†ï¼Œå› ä¸ºåŽŸåž‹ä¸éœ€è¦å®žçŽ°å®žä½“ç±»ã€‚ç„¶è€Œï¼Œä½ æ— "
"法进行编译期的类型检查,并å¯èƒ½ç”±æ¤ä¼šå¤„ç†å¾ˆå¤šçš„è¿è¡ŒæœŸå¼‚常。幸äºæœ‰äº† Hibernate "
"æ˜ å°„ï¼Œå®ƒä½¿å¾—æ•°æ®åº“çš„ schema èƒ½å®¹æ˜“çš„è§„æ ¼åŒ–å’Œåˆç†åŒ–,并å…许ç¨åŽåœ¨æ¤ä¹‹ä¸Šæ·»åŠ åˆ"
"适的领域模型实现。 "
#. Tag: para
#: persistent_classes.xml:290
#, no-c-format
msgid ""
"Entity representation modes can also be set on a per <literal>Session 的基础上设置:"
#. Tag: programlisting
#: persistent_classes.xml:293
#, fuzzy, no-c-format
msgid ""
"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"
msgstr ""
"<![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"
"]]>"
#. Tag: para
#: persistent_classes.xml:295
#, no-c-format
msgid ""
"Please note that the call to <literal>getSession() using an "
"<literal>EntityMode is on the Session API, not "
"the <literal>SessionFactory. That way, the new Sessionclose() on the secondary Session 调用 getSession()Session çš„ API ä¸ï¼Œè€Œä¸æ˜¯ "
"<literal>SessionFactory。 è¿™æ ·ï¼Œæ–°çš„ Session å…±"
"享底层的 JDBC 连接,事务,和其他的上下文信æ¯ã€‚è¿™æ„味ç€ï¼Œä½ ä¸éœ€è¦åœ¨ç¬¬äºŒä¸ª "
"<literal>Session ä¸è°ƒç”¨ flush() å’Œ "
"<literal>close(),åŒæ ·çš„,把事务和连接的处ç†äº¤ç»™åŽŸæ¥çš„工作å•å…ƒã€‚ "
#. Tag: para
#: persistent_classes.xml:304
#, fuzzy, no-c-format
msgid ""
"More information about the XML representation capabilities can be found in "
"<xref linkend=\"xml\"/>."
msgstr "关于 XML 表示能力的更多信æ¯å¯ä»¥åœ¨ <xref linkend=\"xml\"/> ä¸æ‰¾åˆ°ã€‚"
#. Tag: title
#: persistent_classes.xml:310
#, no-c-format
msgid "Tuplizers"
msgstr "元组片æ–æ˜ å°„ï¼ˆTuplizers)"
#. Tag: para
#: persistent_classes.xml:312
#, fuzzy, no-c-format
msgid ""
"<interfacename>org.hibernate.tuple.Tuplizer and its sub-"
"interfaces are responsible for managing a particular representation of a "
"piece of data given that representation's <classname>org.hibernate."
"EntityMode</classname>. If a given piece of data is thought of as a data "
"structure, then a tuplizer is the thing that knows how to create such a data "
"structure, how to extract values from such a data structure and how to "
"inject values into such a data structure. For example, for the POJO entity "
"mode, the corresponding tuplizer knows how create the POJO through its "
"constructor. It also knows how to access the POJO properties using the "
"defined property accessors."
msgstr ""
"<literal>org.hibernate.tuple.Tuplizer,以åŠå…¶å接å£ï¼Œè´Ÿè´£æ ¹æ®ç»™å®šçš„"
"<literal>org.hibernate.EntityMode,æ¥å¤çŽ°ç‰‡æ–æ•°æ®ã€‚如果给定的片æ–æ•°"
"æ®è¢«è®¤ä¸ºå…¶æ˜¯ä¸€ç§æ•°æ®ç»“构,\"tuplizer\" 就是一个知é“å¦‚ä½•åˆ›å»ºè¿™æ ·çš„æ•°æ®ç»“构,以"
"åŠå¦‚何给这个数æ®ç»“构赋值的东西。比如说,对于 POJO è¿™ç§ Entity Mode,对应的 "
"tuplizer 知é“é€šè¿‡å…¶æž„é€ æ–¹æ³•æ¥åˆ›å»ºä¸€ä¸ª POJO,å†é€šè¿‡å…¶å±žæ€§è®¿é—®å™¨æ¥è®¿é—® POJO 属"
"性。有两大类高层 Tuplizer,分别是<literal>org.hibernate.tuple.entity."
"EntityTuplizer</literal> 和 org.hibernate.tuple.entity."
"ComponentTuplizer</literal> 接å£ã€‚EntityTuplizer 负责管ç†"
"上é¢æ到的实体的契约,而 <literal>ComponentTuplizer 则是针对组件"
"的。 "
#. Tag: para
#: persistent_classes.xml:322
#, no-c-format
msgid "There are two (high-level) types of Tuplizers:"
msgstr ""
#. Tag: para
#: persistent_classes.xml:326
#, no-c-format
msgid ""
"<interfacename>org.hibernate.tuple.entity.EntityTuplizer "
"which is responsible for managing the above mentioned contracts in regards "
"to entities"
msgstr ""
#. Tag: para
#: persistent_classes.xml:332
#, no-c-format
msgid ""
"<interfacename>org.hibernate.tuple.component.ComponentTuplizer implementation other than "
"<classname>java.util.HashMap 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. Tuplizer definitions are attached to the "
"entity or component mapping they are meant to manage. Going back to the "
"example of our <classname>Customer entity, "
"using annotations while <xref linkend=\"example-specify-custom-tuplizer-xml"
"\"/> shows how to do the same in <literal>hbm.xml"
msgstr ""
"用户也å¯ä»¥æ’入其自定义的 tuplizer。或许您需è¦ä¸€ç§ä¸åŒäºŽ dynamic-map entity-"
"mode ä¸ä½¿ç”¨çš„ <literal>java.util.HashMap çš„ java.util."
"Map</literal> 实现;或许您需è¦ä¸Žé»˜è®¤ç–ç•¥ä¸åŒçš„代ç†ç”Ÿæˆç–略(proxy generation "
"strategy)。通过自定义 tuplizer å®žçŽ°ï¼Œè¿™ä¸¤ä¸ªç›®æ ‡æ‚¨éƒ½å¯ä»¥è¾¾åˆ°ã€‚Tuplizer 定义被"
"é™„åŠ åˆ°å®ƒä»¬æœŸæœ›ç®¡ç†çš„ entity 或者 component æ˜ å°„ä¸ã€‚回到我们的 customer "
"entity 例å: "
#. Tag: title
#: persistent_classes.xml:353
#, no-c-format
msgid "Specify custom tuplizers in annotations"
msgstr ""
#. Tag: programlisting
#: persistent_classes.xml:354
#, no-c-format
msgid ""
"@Entity\n"
"@Tuplizer(impl = DynamicEntityTuplizer.class)\n"
"public interface Cuisine {\n"
" @Id\n"
" @GeneratedValue\n"
" public Long getId();\n"
" public void setId(Long id);\n"
"\n"
" public String getName();\n"
" public void setName(String name);\n"
"\n"
" @Tuplizer(impl = DynamicComponentTuplizer.class)\n"
" public Country getCountry();\n"
" public void setCountry(Country country);\n"
"}"
msgstr ""
#. Tag: title
#: persistent_classes.xml:357
#, no-c-format
msgid "Specify custom tuplizers in <literal>hbm.xml"
msgstr ""
#. Tag: programlisting
#: persistent_classes.xml:358
#, no-c-format
msgid ""
"<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>"
msgstr ""
#. Tag: title
#: persistent_classes.xml:363
#, no-c-format
msgid "EntityNameResolvers"
msgstr "EntityNameResolvers"
#. Tag: para
#: persistent_classes.xml:365
#, fuzzy, no-c-format
msgid ""
"<interfacename>org.hibernate.EntityNameResolver is a "
"contract for resolving the entity name of a given entity instance. The "
"interface defines a single method <methodname>resolveEntityName "
"which is passed the entity instance and is expected to return the "
"appropriate entity name (null is allowed and would indicate that the "
"resolver does not know how to resolve the entity name of the given entity "
"instance). Generally speaking, an <interfacename>org.hibernate."
"EntityNameResolver</interfacename> is going to be most useful in the case of "
"dynamic models. One example might be using proxied interfaces as your domain "
"model. The hibernate test suite has an example of this exact style of usage "
"under the <package>org.hibernate.test.dynamicentity.tuplizer2. "
"Here is some of the code from that package for illustration."
msgstr ""
"<interfacename>org.hibernate.EntityNameResolver 接å£æ˜¯ä¸€ä¸ªè§£"
"æžç»™å®šå®žä½“实例的实体å称的åˆçº¦ã€‚这个接å£å®šä¹‰äº†ä¸€ä¸ªå•ä¸€çš„方法 "
"<methodname>resolveEntityNameï¼Œå®ƒä¼ é€’å®žä½“å®žä¾‹å¹¶é¢„æœŸè¿”å›žåˆé€‚的实"
"体å称(null 指明解æžå™¨ä¸çŸ¥é“如何解æžç»™å®šå®žä½“实例的实体å称)。一般说æ¥ï¼Œ"
"<interfacename>org.hibernate.EntityNameResolver 在动æ€æ¨¡åž‹é‡Œ"
"最为有用。其ä¸çš„例å是把代ç†æŽ¥å£ç”¨ä½œä½ 的域模型。Hibernate Test Suite 在 "
"<package>org.hibernate.test.dynamicentity.tuplizer2 下有具有完全相"
"åŒé£Žæ ¼çš„例å。下é¢æ˜¯è¯¥åŒ…里的一些代ç :"
#. Tag: programlisting
#: persistent_classes.xml:377
#, fuzzy, no-c-format
msgid ""
"/**\n"
" * A very trivial JDK Proxy InvocationHandler implementation where we proxy "
"an\n"
" * interface as the domain model and simply store persistent state in an "
"internal\n"
" * Map. This is an extremely trivial example meant only for illustration.\n"
" */\n"
"public final class DataProxyHandler implements InvocationHandler {\n"
" private String entityName;\n"
" private HashMap data = new HashMap();\n"
"\n"
" public DataProxyHandler(String entityName, Serializable id) {\n"
" this.entityName = entityName;\n"
" data.put( \"Id\", id );\n"
" }\n"
"\n"
" public Object invoke(Object proxy, Method method, Object[] args) "
"throws Throwable {\n"
" String methodName = method.getName();\n"
" if ( methodName.startsWith( \"set\" ) ) {\n"
" String propertyName = methodName.substring( 3 );\n"
" data.put( propertyName, args[0] );\n"
" }\n"
" else if ( methodName.startsWith( \"get\" ) ) {\n"
" String propertyName = methodName.substring( 3 );\n"
" return data.get( propertyName );\n"
" }\n"
" else if ( \"toString\".equals( methodName ) ) {\n"
" return entityName + \"#\" + data.get( \"Id\" );\n"
" }\n"
" else if ( \"hashCode\".equals( methodName ) ) {\n"
" return new Integer( this.hashCode() );\n"
" }\n"
" return null;\n"
" }\n"
"\n"
" public String getEntityName() {\n"
" return entityName;\n"
" }\n"
"\n"
" public HashMap getData() {\n"
" return data;\n"
" }\n"
"}\n"
"\n"
"public class ProxyHelper {\n"
" public static String extractEntityName(Object object) {\n"
" // Our custom java.lang.reflect.Proxy instances actually bundle\n"
" // their appropriate entity name, so we simply extract it from "
"there\n"
" // if this represents one of our proxies; otherwise, we return null\n"
" if ( Proxy.isProxyClass( object.getClass() ) ) {\n"
" InvocationHandler handler = Proxy.getInvocationHandler"
"( object );\n"
" if ( DataProxyHandler.class.isAssignableFrom( handler.getClass"
"() ) ) {\n"
" DataProxyHandler myHandler = ( DataProxyHandler ) handler;\n"
" return myHandler.getEntityName();\n"
" }\n"
" }\n"
" return null;\n"
" }\n"
"\n"
" // various other utility methods ....\n"
"\n"
"}\n"
"\n"
"/**\n"
" * The EntityNameResolver implementation.\n"
" *\n"
" * IMPL NOTE : An EntityNameResolver really defines a strategy for how "
"entity names\n"
" * should be resolved. Since this particular impl can handle resolution for "
"all of our\n"
" * entities we want to take advantage of the fact that SessionFactoryImpl "
"keeps these\n"
" * in a Set so that we only ever have one instance registered. Why? Well, "
"when it\n"
" * comes time to resolve an entity name, Hibernate must iterate over all the "
"registered\n"
" * resolvers. So keeping that number down helps that process be as speedy "
"as possible.\n"
" * Hence the equals and hashCode implementations as is\n"
" */\n"
"public class MyEntityNameResolver implements EntityNameResolver {\n"
" public static final MyEntityNameResolver INSTANCE = new "
"MyEntityNameResolver();\n"
"\n"
" public String resolveEntityName(Object entity) {\n"
" return ProxyHelper.extractEntityName( entity );\n"
" }\n"
"\n"
" public boolean equals(Object obj) {\n"
" return getClass().equals( obj.getClass() );\n"
" }\n"
"\n"
" public int hashCode() {\n"
" return getClass().hashCode();\n"
" }\n"
"}\n"
"\n"
"public class MyEntityTuplizer extends PojoEntityTuplizer {\n"
" public MyEntityTuplizer(EntityMetamodel entityMetamodel, "
"PersistentClass mappedEntity) {\n"
" super( entityMetamodel, mappedEntity );\n"
" }\n"
"\n"
" public EntityNameResolver[] getEntityNameResolvers() {\n"
" return new EntityNameResolver[] { MyEntityNameResolver."
"INSTANCE };\n"
" }\n"
"\n"
" public String determineConcreteSubclassEntityName(Object entityInstance, "
"SessionFactoryImplementor factory) {\n"
" String entityName = ProxyHelper.extractEntityName"
"( entityInstance );\n"
" if ( entityName == null ) {\n"
" entityName = super.determineConcreteSubclassEntityName"
"( entityInstance, factory );\n"
" }\n"
" return entityName;\n"
" }\n"
"\n"
" ..."
msgstr ""
"/**\n"
" * A very trivial JDK Proxy InvocationHandler implementation where we proxy "
"an interface as\n"
" * the domain model and simply store persistent state in an internal Map. "
"This is an extremely\n"
" * trivial example meant only for illustration.\n"
" */\n"
"public final class DataProxyHandler implements InvocationHandler {\n"
" private String entityName;\n"
" private HashMap data = new HashMap();\n"
"\n"
" public DataProxyHandler(String entityName, Serializable id) {\n"
" this.entityName = entityName;\n"
" data.put( \"Id\", id );\n"
" }\n"
"\n"
" public Object invoke(Object proxy, Method method, Object[] args) "
"throws Throwable {\n"
" String methodName = method.getName();\n"
" if ( methodName.startsWith( \"set\" ) ) {\n"
" String propertyName = methodName.substring( 3 );\n"
" data.put( propertyName, args[0] );\n"
" }\n"
" else if ( methodName.startsWith( \"get\" ) ) {\n"
" String propertyName = methodName.substring( 3 );\n"
" return data.get( propertyName );\n"
" }\n"
" else if ( \"toString\".equals( methodName ) ) {\n"
" return entityName + \"#\" + data.get( \"Id\" );\n"
" }\n"
" else if ( \"hashCode\".equals( methodName ) ) {\n"
" return new Integer( this.hashCode() );\n"
" }\n"
" return null;\n"
" }\n"
"\n"
" public String getEntityName() {\n"
" return entityName;\n"
" }\n"
"\n"
" public HashMap getData() {\n"
" return data;\n"
" }\n"
"}\n"
"\n"
"/**\n"
" *\n"
" */\n"
"public class ProxyHelper {\n"
" public static String extractEntityName(Object object) {\n"
" // Our custom java.lang.reflect.Proxy instances actually bundle\n"
" // their appropriate entity name, so we simply extract it from "
"there\n"
" // if this represents one of our proxies; otherwise, we return null\n"
" if ( Proxy.isProxyClass( object.getClass() ) ) {\n"
" InvocationHandler handler = Proxy.getInvocationHandler"
"( object );\n"
" if ( DataProxyHandler.class.isAssignableFrom( handler.getClass"
"() ) ) {\n"
" DataProxyHandler myHandler = ( DataProxyHandler ) handler;\n"
" return myHandler.getEntityName();\n"
" }\n"
" }\n"
" return null;\n"
" }\n"
"\n"
" // various other utility methods ....\n"
"\n"
"}\n"
"\n"
"/**\n"
" * The EntityNameResolver implementation.\n"
" * IMPL NOTE : An EntityNameResolver really defines a strategy for how "
"entity names should be\n"
" * resolved. Since this particular impl can handle resolution for all of "
"our entities we want to\n"
" * take advantage of the fact that SessionFactoryImpl keeps these in a Set "
"so that we only ever\n"
" * have one instance registered. Why? Well, when it comes time to resolve "
"an entity name,\n"
" * Hibernate must iterate over all the registered resolvers. So keeping "
"that number down\n"
" * helps that process be as speedy as possible. Hence the equals and "
"hashCode impls\n"
" */\n"
"public class MyEntityNameResolver implements EntityNameResolver {\n"
" public static final MyEntityNameResolver INSTANCE = new "
"MyEntityNameResolver();\n"
"\n"
" public String resolveEntityName(Object entity) {\n"
" return ProxyHelper.extractEntityName( entity );\n"
" }\n"
"\n"
" public boolean equals(Object obj) {\n"
" return getClass().equals( obj.getClass() );\n"
" }\n"
"\n"
" public int hashCode() {\n"
" return getClass().hashCode();\n"
" }\n"
"}\n"
"\n"
"public class MyEntityTuplizer extends PojoEntityTuplizer {\n"
" public MyEntityTuplizer(EntityMetamodel entityMetamodel, "
"PersistentClass mappedEntity) {\n"
" super( entityMetamodel, mappedEntity );\n"
" }\n"
"\n"
" public EntityNameResolver[] getEntityNameResolvers() {\n"
" return new EntityNameResolver[] { MyEntityNameResolver."
"INSTANCE };\n"
" }\n"
"\n"
" public String determineConcreteSubclassEntityName(Object entityInstance, "
"SessionFactoryImplementor factory) {\n"
" String entityName = ProxyHelper.extractEntityName"
"( entityInstance );\n"
" if ( entityName == null ) {\n"
" entityName = super.determineConcreteSubclassEntityName"
"( entityInstance, factory );\n"
" }\n"
" return entityName;\n"
" }\n"
"\n"
" ...\n"
"}"
#. Tag: para
#: persistent_classes.xml:379
#, no-c-format
msgid ""
"In order to register an <interfacename>org.hibernate.EntityNameResolver,用"
"户必须:"
#. Tag: para
#: persistent_classes.xml:383
#, fuzzy, no-c-format
msgid ""
"Implement a custom tuplizer (see <xref linkend=\"persistent-classes-tuplizers"
"\"/>), implementing the <methodname>getEntityNameResolvers "
"method"
msgstr ""
"实现自定义的 <link linkend=\"persistent-classes-tuplizers\">Tuplizer "
"并实现 <methodname>getEntityNameResolvers 方法。"
#. Tag: para
#: persistent_classes.xml:389
#, no-c-format
msgid ""
"Register it with the <classname>org.hibernate.impl.SessionFactoryImplorg."
"hibernate.SessionFactory</interfacename>) using the "
"<methodname>registerEntityNameResolver method."
msgstr ""
"用 <methodname>registerEntityNameResolver 方法注册到 "
"<classname>org.hibernate.impl.SessionFactoryImpl(它是 "
"<interfacename>org.hibernate.SessionFactory 的实现类)。"
#~ msgid ""
#~ "Most Java applications require a persistent class representing felines. "
#~ "For example:"
#~ msgstr "大多数 Java 程åºéœ€è¦ç”¨ä¸€ä¸ªæŒä¹…化类æ¥è¡¨ç¤ºçŒ«ç§‘动物。例如:"
#~ msgid ""
#~ "<literal>Cat has a property called id. This "
#~ "property maps to the primary key column of a database table. The property "
#~ "might have been called anything, and its type might have been any "
#~ "primitive type, any primitive \"wrapper\" type, <literal>java.lang."
#~ "String</literal> or java.util.Date. If your legacy "
#~ "database table has composite keys, you can use a user-defined class with "
#~ "properties of these types (see the section on composite identifiers later "
#~ "in the chapter.)"
#~ msgstr ""
#~ "<literal>Cat 有一个属性å«åš idã€‚è¿™ä¸ªå±žæ€§æ˜ å°„"
#~ "æ•°æ®åº“表的主 é”®å—段。这个属性å¯ä»¥å«ä»»ä½•åå—,其类型å¯ä»¥æ˜¯ä»»ä½•çš„原始类型ã€"
#~ "原始类型的包装类型〠<literal>java.lang.String 或者是 "
#~ "<literal>java.util.Dateã€‚ï¼ˆå¦‚æžœä½ çš„é—留数æ®åº“表有è”åˆä¸»é”®ï¼Œä½ 甚"
#~ "至å¯ä»¥ç”¨ä¸€ä¸ªç”¨æˆ·è‡ªå®šä¹‰çš„类,该类拥有这些类型的属性。å‚è§åŽé¢çš„关于è”åˆæ ‡è¯†"
#~ "ç¬¦çš„ç« èŠ‚ã€‚ï¼‰"
#~ msgid ""
#~ "The identifier property is strictly optional. You can leave them off and "
#~ "let Hibernate keep track of object identifiers internally. We do not "
#~ "recommend this, however."
#~ msgstr ""
#~ "æ ‡è¯†ç¬¦å±žæ€§æ˜¯å¯é€‰çš„。å¯ä»¥ä¸ç”¨ç®¡å®ƒï¼Œè®© Hibernate 内部æ¥è¿½è¸ªå¯¹è±¡çš„识别。 但是"
#~ "我们并ä¸æŽ¨èè¿™æ ·åšã€‚"
#~ msgid ""
#~ "In fact, some functionality is available only to classes that declare an "
#~ "identifier property:"
#~ msgstr "实际上,一些功能åªå¯¹é‚£äº›å£°æ˜Žäº†æ ‡è¯†ç¬¦å±žæ€§çš„类起作用: "
#~ msgid ""
#~ "Transitive reattachment for detached objects (cascade update or cascade "
#~ "merge) - see <xref linkend=\"objectstate-transitive\" />"
#~ msgstr ""
#~ "æ‰˜ç®¡å¯¹è±¡çš„ä¼ æ’性å†è¿žæŽ¥ï¼ˆçº§è”更新或级è”åˆå¹¶ï¼‰- å‚阅 <xref linkend="
#~ "\"objectstate-transitive\"/>"
#~ msgid "<literal>Session.saveOrUpdate()"
#~ msgstr "<literal>Session.saveOrUpdate() "
#~ msgid "<literal>Session.merge()"
#~ msgstr "<literal>Session.merge() "
#~ msgid ""
#~ "A central feature of Hibernate, <emphasis>proxies, depends "
#~ "upon the persistent class being either non-final, or the implementation "
#~ "of an interface that declares all public methods."
#~ msgstr ""
#~ "<emphasis>代ç†ï¼ˆproxies)是 Hibernate 的一个é‡è¦çš„功能,它ä¾èµ–"
#~ "çš„æ¡ä»¶æ˜¯ï¼ŒæŒä¹…åŒ–ç±»æˆ–è€…æ˜¯éž final 的,或者是实现了一个所有方法都声明为 "
#~ "public 的接å£ã€‚"
#~ msgid ""
#~ "You can persist <literal>final classes that do not implement an "
#~ "interface with Hibernate. You will not, however, be able to use proxies "
#~ "for lazy association fetching which will ultimately limit your options "
#~ "for performance tuning."
#~ msgstr ""
#~ "ä½ å¯ä»¥ç”¨ Hibernate æŒä¹…化一个没有实现任何接å£çš„ <literal>final "
#~ "ç±»ï¼Œä½†æ˜¯ä½ ä¸èƒ½ä½¿ç”¨ä»£ç†æ¥å»¶è¿Ÿå…³è”åŠ è½½ï¼Œè¿™ä¼šé™åˆ¶ä½ 进行性能优化的选择。 "
#~ msgid ""
#~ "There are two high-level types of Tuplizers, represented by the "
#~ "<literal>org.hibernate.tuple.entity.EntityTuplizer and "
#~ "<literal>org.hibernate.tuple.component.ComponentTuplizer "
#~ "interfaces. <literal>EntityTuplizers are responsible for "
#~ "managing the above mentioned contracts in regards to entities, while "
#~ "<literal>ComponentTuplizers do the same for components."
#~ msgstr ""
#~ "有两ç§é«˜å±‚类型的 Tuplizer,分别由 <literal>org.hibernate.tuple.entity."
#~ "EntityTuplizer</literal> 和 org.hibernate.tuple.component."
#~ "ComponentTuplizer</literal> 接å£ä»£è¡¨ã€‚EntityTuplizer è´Ÿ"
#~ "责管ç†å’Œå®žä½“相关的上述åˆçº¦ï¼Œè€Œ<literal>ComponentTuplizer 则负责"
#~ "组件。"
#~ msgid ""
#~ "<![CDATA[
Other Hibernate examples (source code examples)
Here is a short list of links related to this Hibernate persistent_classes.po source code file:
|