📄 session_api.po
字号:
msgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: http://bugs.kde.org\n""POT-Creation-Date: 2008-08-14 15:28+0000\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <LL@li.org>\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"#. Tag: title#: session_api.xml:29#, no-c-formatmsgid "Working with objects"msgstr "与对象共事"#. Tag: para#: session_api.xml:31#, no-c-formatmsgid """Hibernate is a full object/relational mapping solution that not only shields ""the developer from the details of the underlying database management system, ""but also offers <emphasis>state management</emphasis> of objects. This is, ""contrary to the management of SQL <literal>statements</literal> in common ""JDBC/SQL persistence layers, a very natural object-oriented view of ""persistence in Java applications."msgstr """Hibernate是完整的对象/关系映射解决方案,它提供了对象<emphasis>状态管理(state ""management)</emphasis>的功能,使开发者不再需要理会底层数据库系统的细节。 也就""是说,相对于常见的JDBC/SQL持久层方案中需要<literal>管理SQL语句</literal>,""Hibernate采用了更自然的面向对象的视角来持久化Java应用中的数据。"#. Tag: para#: session_api.xml:40#, no-c-formatmsgid """In other words, Hibernate application developers should always think about ""the <emphasis>state</emphasis> of their objects, and not necessarily about ""the execution of SQL statements. This part is taken care of by Hibernate and ""is only relevant for the application developer when tuning the performance ""of the system."msgstr """换句话说,使用Hibernate的开发者应该总是关注对象的<emphasis>状态(state)</""emphasis>,不必考虑SQL语句的执行。 这部分细节已经由Hibernate掌管妥当,只有开""发者在进行系统性能调优的时候才需要进行了解。"#. Tag: title#: session_api.xml:48#, no-c-formatmsgid "Hibernate object states"msgstr "Hibernate对象状态(object states)"#. Tag: para#: session_api.xml:50#, no-c-formatmsgid "Hibernate defines and supports the following object states:"msgstr "Hibernate定义并支持下列对象状态(state):"#. Tag: para#: session_api.xml:56#, no-c-formatmsgid """<emphasis>Transient</emphasis> - an object is transient if it has just been ""instantiated using the <literal>new</literal> operator, and it is not ""associated with a Hibernate <literal>Session</literal>. It has no persistent ""representation in the database and no identifier value has been assigned. ""Transient instances will be destroyed by the garbage collector if the ""application doesn't hold a reference anymore. Use the Hibernate ""<literal>Session</literal> to make an object persistent (and let Hibernate ""take care of the SQL statements that need to be executed for this ""transition)."msgstr """<emphasis>瞬时(Transient)</emphasis> - 由<literal>new</literal>操作符创建,且""尚未与Hibernate <literal>Session</literal> 关联的对象被认定为瞬时(Transient)""的。瞬时(Transient)对象不会被持久化到数据库中,也不会被赋予持久化标识""(identifier)。 如果瞬时(Transient)对象在程序中没有被引用,它会被垃圾回收器""(garbage collector)销毁。 使用Hibernate <literal>Session</literal>可以将其变""为持久(Persistent)状态。(Hibernate会自动执行必要的SQL语句)"#. Tag: para#: session_api.xml:68#, no-c-formatmsgid """<emphasis>Persistent</emphasis> - a persistent instance has a representation ""in the database and an identifier value. It might just have been saved or ""loaded, however, it is by definition in the scope of a <literal>Session</""literal>. Hibernate will detect any changes made to an object in persistent ""state and synchronize the state with the database when the unit of work ""completes. Developers don't execute manual <literal>UPDATE</literal> ""statements, or <literal>DELETE</literal> statements when an object should be ""made transient."msgstr """<emphasis>持久(Persistent)</emphasis> - 持久(Persistent)的实例在数据库中有对""应的记录,并拥有一个持久化标识(identifier)。 持久(Persistent)的实例可能是刚被""保存的,或刚被加载的,无论哪一种,按定义,它存在于相关联的<literal>Session</""literal>作用范围内。 Hibernate会检测到处于持久(Persistent)状态的对象的任何改""动,在当前操作单元(unit of work)执行完毕时将对象数据(state)与数据库同步""(synchronize)。 开发者不需要手动执行<literal>UPDATE</literal>。将对象从持久""(Persistent)状态变成瞬时(Transient)状态同样也不需要手动执行<literal>DELETE</""literal>语句。"#. Tag: para#: session_api.xml:79#, no-c-formatmsgid """<emphasis>Detached</emphasis> - a detached instance is an object that has ""been persistent, but its <literal>Session</literal> has been closed. The ""reference to the object is still valid, of course, and the detached instance ""might even be modified in this state. A detached instance can be reattached ""to a new <literal>Session</literal> at a later point in time, making it (and ""all the modifications) persistent again. This feature enables a programming ""model for long running units of work that require user think-time. We call ""them <emphasis>application transactions</emphasis>, i.e. a unit of work from ""the point of view of the user."msgstr """<emphasis>脱管(Detached)</emphasis> - 与持久(Persistent)对象关联的""<literal>Session</literal>被关闭后,对象就变为脱管(Detached)的。 对脱管""(Detached)对象的引用依然有效,对象可继续被修改。脱管(Detached)对象如果重新关""联到某个新的<literal>Session</literal>上, 会再次转变为持久(Persistent)的(在""Detached其间的改动将被持久化到数据库)。 这个功能使得一种编程模型,即中间会给""用户思考时间(user think-time)的长时间运行的操作单元(unit of work)的编程模型成""为可能。 我们称之为<emphasis>应用程序事务</emphasis>,即从用户观点看是一个操""作单元(unit of work)。"#. Tag: para#: session_api.xml:93#, no-c-formatmsgid """We'll now discuss the states and state transitions (and the Hibernate ""methods that trigger a transition) in more detail."msgstr """接下来我们来细致的讨论下状态(states)及状态间的转换(state transitions)(以及触""发状态转换的Hibernate方法)。"#. Tag: title#: session_api.xml:101#, no-c-formatmsgid "Making objects persistent"msgstr "使对象持久化"#. Tag: para#: session_api.xml:103#, no-c-formatmsgid """Newly instantiated instances of a a persistent class are considered ""<emphasis>transient</emphasis> by Hibernate. We can make a transient ""instance <emphasis>persistent</emphasis> by associating it with a session:"msgstr """Hibernate认为持久化类(persistent class)新实例化的对象是<emphasis>瞬时""(Transient)</emphasis>的。 我们可通过将瞬时(Transient)对象与session关联而把它""变为<emphasis>持久(Persistent)</emphasis>的。"#. Tag: programlisting#: session_api.xml:110#, no-c-formatmsgid """<![CDATA[DomesticCat fritz = new DomesticCat();\n""fritz.setColor(Color.GINGER);\n""fritz.setSex('M');\n""fritz.setName(\"Fritz\");\n""Long generatedId = (Long) sess.save(fritz);]]>"msgstr ""#. Tag: para#: session_api.xml:112#, no-c-formatmsgid """If <literal>Cat</literal> has a generated identifier, the identifier is ""generated and assigned to the <literal>cat</literal> when <literal>save()</""literal> is called. If <literal>Cat</literal> has an <literal>assigned</""literal> identifier, or a composite key, the identifier should be assigned ""to the <literal>cat</literal> instance before calling <literal>save()</""literal>. You may also use <literal>persist()</literal> instead of ""<literal>save()</literal>, with the semantics defined in the EJB3 early ""draft."msgstr """如果<literal>Cat</literal>的持久化标识(identifier)是<literal>generated</""literal>类型的, 那么该标识(identifier)会自动在<literal>save()</literal>被调""用时产生并分配给<literal>cat</literal>。 如果<literal>Cat</literal>的持久化标""识(identifier)是<literal>assigned</literal>类型的,或是一个复合主键""(composite key), 那么该标识(identifier)应当在调用<literal>save()</literal>之""前手动赋予给<literal>cat</literal>。 你也可以按照EJB3 early draft中定义的语""义,使用<literal>persist()</literal>替代<literal>save()</literal>。"#. Tag: para#: session_api.xml:124#, no-c-formatmsgid """<literal>persist()</literal> makes a transient instance persistent. However, ""it doesn't guarantee that the identifier value will be assigned to the ""persistent instance immediately, the assignment might happen at flush time. ""<literal>persist()</literal> also guarantees that it will not execute an ""<literal>INSERT</literal> statement if it is called outside of transaction ""boundaries. This is useful in long-running conversations with an extended ""Session/persistence context."msgstr """<literal>persist()</literal> makes a transient instance persistent. However, ""it doesn't guarantee that the identifier value will be assigned to the ""persistent instance immediately, the assignment might happen at flush time. ""<literal>persist()</literal> also guarantees that it will not execute an ""<literal>INSERT</literal> statement if it is called outside of transaction ""boundaries. This is useful in long-running conversations with an extended ""Session/persistence context."#. Tag: para#: session_api.xml:135#, no-c-formatmsgid """<literal>save()</literal> does guarantee to return an identifier. If an ""INSERT has to be executed to get the identifier ( e.g. \"identity\" ""generator, not \"sequence\"), this INSERT happens immediately, no matter if ""you are inside or outside of a transaction. This is problematic in a long-""running conversation with an extended Session/persistence context."msgstr """<literal>save()</literal> does guarantee to return an identifier. If an ""INSERT has to be executed to get the identifier ( e.g. \"identity\" ""generator, not \"sequence\"), this INSERT happens immediately, no matter if ""you are inside or outside of a transaction. This is problematic in a long-""running conversation with an extended Session/persistence context."#. Tag: para#: session_api.xml:145#, no-c-formatmsgid """Alternatively, you may assign the identifier using an overloaded version of ""<literal>save()</literal>."msgstr "此外,你可以用一个重载版本的<literal>save()</literal>方法。"#. Tag: programlisting#: session_api.xml:150#, no-c-formatmsgid """<![CDATA[DomesticCat pk = new DomesticCat();\n""pk.setColor(Color.TABBY);\n""pk.setSex('F');\n""pk.setName(\"PK\");\n""pk.setKittens( new HashSet() );\n""pk.addKitten(fritz);\n""sess.save( pk, new Long(1234) );]]>"msgstr ""#. Tag: para#: session_api.xml:152#, no-c-formatmsgid """If the object you make persistent has associated objects (e.g. the ""<literal>kittens</literal> collection in the previous example), these ""objects may be made persistent in any order you like unless you have a ""<literal>NOT NULL</literal> constraint upon a foreign key column. There is ""never a risk of violating foreign key constraints. However, you might ""violate a <literal>NOT NULL</literal> constraint if you <literal>save()</""literal> the objects in the wrong order."msgstr """如果你持久化的对象有关联的对象(associated objects)(例如上例中的""<literal>kittens</literal>集合) 那么对这些对象(译注:pk和kittens)进行持久""化的顺序是任意的(也就是说可以先对kittens进行持久化也可以先对pk进行持久""化), 除非你在外键列上有<literal>NOT NULL</literal>约束。 Hibernate不会违反""外键约束,但是如果你用错误的顺序持久化对象(译注:在pk持久化之前持久化""kitten),那么可能会违反<literal>NOT NULL</literal>约束。"#. Tag: para#: session_api.xml:162#, no-c-formatmsgid """Usually you don't bother with this detail, as you'll very likely use ""Hibernate's <emphasis>transitive persistence</emphasis> feature to save the ""associated objects automatically. Then, even <literal>NOT NULL</literal> ""constraint violations don't occur - Hibernate will take care of everything. ""Transitive persistence is discussed later in this chapter."msgstr """通常你不会为这些细节烦心,因为你很可能会使用Hibernate的 <emphasis>传播性持久""化(transitive persistence)</emphasis>功能自动保存相关联那些对象。 这样连违反""<literal>NOT NULL</literal>约束的情况都不会出现了 - Hibernate会管好所有的事""情。 传播性持久化(transitive persistence)将在本章稍后讨论。"#. Tag: title#: session_api.xml:173#, no-c-formatmsgid "Loading an object"msgstr "装载对象"#. Tag: para#: session_api.xml:175#, no-c-formatmsgid """The <literal>load()</literal> methods of <literal>Session</literal> gives ""you a way to retrieve a persistent instance if you already know its ""identifier. <literal>load()</literal> takes a class object and will load the ""state into a newly instantiated instance of that class, in persistent state."msgstr """如果你知道某个实例的持久化标识(identifier),你就可以使用<literal>Session</""literal>的<literal>load()</literal>方法 来获取它。 <literal>load()</literal>""的另一个参数是指定类的.class对象。 本方法会创建指定类的持久化实例,并从数据库""加载其数据(state)。"#. Tag: programlisting#: session_api.xml:182#, no-c-formatmsgid "<![CDATA[Cat fritz = (Cat) sess.load(Cat.class, generatedId);]]>"msgstr ""#. Tag: programlisting#: session_api.xml:184#, no-c-formatmsgid """<![CDATA[// you need to wrap primitive identifiers\n""long id = 1234;\n""DomesticCat pk = (DomesticCat) sess.load( DomesticCat.class, new Long""(id) );]]>"msgstr ""#. Tag: para#: session_api.xml:186#, no-c-formatmsgid "Alternatively, you can load state into a given instance:"msgstr """此外, 你可以把数据(state)加载到指定的对象实例上(覆盖掉该实例原来的数据)。"#. Tag: programlisting#: session_api.xml:190#, no-c-formatmsgid """<![CDATA[Cat cat = new DomesticCat();\n""// load pk's state into cat\n""sess.load( cat, new Long(pkId) );\n""Set kittens = cat.getKittens();]]>"msgstr ""#. Tag: para#: session_api.xml:192#, no-c-formatmsgid """Note that <literal>load()</literal> will throw an unrecoverable exception if ""there is no matching database row. If the class is mapped with a proxy, ""<literal>load()</literal> just returns an uninitialized proxy and does not ""actually hit the database until you invoke a method of the proxy. This ""behaviour is very useful if you wish to create an association to an object ""without actually loading it from the database. It also allows multiple ""instances to be loaded as a batch if <literal>batch-size</literal> is ""defined for the class mapping."msgstr ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -