⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_parentchild.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 2 页
字号:
#, fuzzymsgid ""msgstr """PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Content-Type: text/plain; charset=utf-8\n"#: index.docbook:5msgid "Example: Parent/Child"msgstr "Ejemplo: Padre/Hijo"#: index.docbook:7msgid """One of the very first things that new users try to do with Hibernate is to ""model a parent / child type relationship. There are two different approaches ""to this. For various reasons the most convenient approach, especially for ""new users, is to model both <literal>Parent</literal> and <literal>Child</""literal> as entity classes with a <literal>&lt;one-to-many&gt;</literal> ""association from <literal>Parent</literal> to <literal>Child</literal>. (The ""alternative approach is to declare the <literal>Child</literal> as a ""<literal>&lt;composite-element&gt;</literal>.) Now, it turns out that ""default semantics of a one to many association (in Hibernate) are much less ""close to the usual semantics of a parent / child relationship than those of ""a composite element mapping. We will explain how to use a ""<emphasis>bidirectional one to many association with cascades</emphasis> to ""model a parent / child relationship efficiently and elegantly. It's not at ""all difficult!"msgstr """Una de las primer&#x00ed;simas cosas que los usuarios nuevos intentan hacer ""con Hibernate es modelar una relaci&#x00f3;n de tipo padre / hijo. Para esto ""hay dos enfoques diferentes. Por varias razones, el enfoque m&#x00e1;s ""conveniente, especialmente para usuarios nuevos, es modelar tanto ""<literal>Parent</literal> como <literal>Child</literal> como clases de ""entidad con una asociaci&#x00f3;n <literal>&lt;one-to-many&gt;</literal> ""desde <literal>Parent</literal> a <literal>Child</literal>. (El enfoque ""alternativo es declarar el <literal>Child</literal> como un <literal>&lt;""composite-element&gt;</literal>.) Ahora, resulta que la sem&#x00e1;ntica por ""defecto de una asociaci&#x00f3;n uno a muchos (en Hibernate) es mucho menos ""cercana a la sem&#x00e1;ntica usual de una relaci&#x00f3;n padre / hijo que ""aquellas de un mapeo de elementos compuestos. Explicaremos c&#x00f3;mo usar ""una <emphasis>asociaci&#x00f3;n uno a muchos bidireccional con tratamiento ""en cascada</emphasis> para modelar una relaci&#x00f3;n padre / hijo ""eficiente y elegantemente. &#x00a1;No es para nada dif&#x00ed;cil!"#: index.docbook:21msgid "A note about collections"msgstr "Una nota sobre las colecciones"#: index.docbook:23msgid """Hibernate collections are considered to be a logical part of their owning ""entity; never of the contained entities. This is a crucial distinction! It ""has the following consequences:"msgstr """Se considera que las colecciones de Hibernate son una parte l&#x00f3;gica de ""la entidad que las posee; nunca de las entidades contenidas. &#x00a1;Esta es ""una distinci&#x00f3;n crucial! Esto tiene las siguientes consecuencias:"#: index.docbook:30msgid """When we remove / add an object from / to a collection, the version number of ""the collection owner is incremented."msgstr """Cuando se quita / a&#x00f1;ade un objeto desde / a una colecci&#x00f3;n, se ""incrementa el n&#x00fa;mero de versi&#x00f3;n del due&#x00f1;o de la ""colecci&#x00f3;n."#: index.docbook:36msgid """If an object that was removed from a collection is an instance of a value ""type (eg, a composite element), that object will cease to be persistent and ""its state will be completely removed from the database. Likewise, adding a ""value type instance to the collection will cause its state to be immediately ""persistent."msgstr """Si un objeto que fue quitado de una colecci&#x00f3;n es una instancia de un ""tipo de valor (por ejemplo, un elemento compuesto), ese objeta cesar&#x00e1; ""de ser persistente y su estado ser&#x00e1; completamente quitado de la base ""de datos. Asimismo, a&#x00f1;adir una instancia de tipo de valor a la ""colecci&#x00f3;n causar&#x00e1; que su estado sea inmediatamente persistente."#: index.docbook:44msgid """On the other hand, if an entity is removed from a collection (a one-to-many ""or many-to-many association), it will not be deleted, by default. This ""behaviour is completely consistent - a change to the internal state of ""another entity should not cause the associated entity to vanish! Likewise, ""adding an entity to a collection does not cause that entity to become ""persistent, by default."msgstr """Por otro lado, si se quita una entidad de una colecci&#x00f3;n (una ""asociaci&#x00f3;n uno-a-muchos o muchos-a-muchos), no ser&#x00e1; borrado, ""por defecto. Este comportamiento es completamente consistente. &#x00a1;Un ""cambio en el estado interno de otra entidad no hace desaparecer la entidad ""asociada! Asimismo, a&#x00f1;adir una entidad a una colecci&#x00f3;n no ""causa que la entidad se vuelva persistente, por defecto."#: index.docbook:54msgid """Instead, the default behaviour is that adding an entity to a collection ""merely creates a link between the two entities, while removing it removes ""the link. This is very appropriate for all sorts of cases. Where it is not ""appropriate at all is the case of a parent / child relationship, where the ""life of the child is bound to the life cycle of the parent."msgstr """En cambio, el comportamiento por defecto es que al a&#x00f1;adir una entidad ""a una colecci&#x00f3;n se crea meramente un enlace entre las dos entidades, ""mientras que al quitarla se quita el enlace. Esto es muy apropiado para ""todos los tipos de casos. Donde no es para nada apropiado es en el caso de ""una relaci&#x00f3;n padre / hijo. donde la vida del hijo est&#x00e1; ligada ""al ciclo de vida del padre."#: index.docbook:64msgid "Bidirectional one-to-many"msgstr "Uno-a-muchos bidirectional"#: index.docbook:66msgid """Suppose we start with a simple <literal>&lt;one-to-many&gt;</literal> ""association from <literal>Parent</literal> to <literal>Child</literal>."msgstr """Sup&#x00f3;n que empezamos con una asociaci&#x00f3;n simple <literal>&lt;one-""to-many&gt;</literal> desde <literal>Parent</literal> a <literal>Child</""literal>."#: index.docbook:71msgid """<![CDATA[<set name=\"children\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr """<![CDATA[<set name=\"children\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"#: index.docbook:73msgid "If we were to execute the following code"msgstr "Si ejecut&#x00e1;semos el siguiente c&#x00f3;digo"#: index.docbook:77msgid """<![CDATA[Parent p = .....;\n""Child c = new Child();\n""p.getChildren().add(c);\n""session.save(c);\n""session.flush();]]>"msgstr """<![CDATA[Parent p = .....;\n""Child c = new Child();\n""p.getChildren().add(c);\n""session.save(c);\n""session.flush();]]>"#: index.docbook:79msgid "Hibernate would issue two SQL statements:"msgstr "Hibernate publicar&#x00ed;a dos sentencias SQL:"#: index.docbook:85msgid """an <literal>INSERT</literal> to create the record for <literal>c</literal>"msgstr """un <literal>INSERT</literal> para crear el registro de <literal>c</literal>"#: index.docbook:88msgid """an <literal>UPDATE</literal> to create the link from <literal>p</literal> to ""<literal>c</literal>"msgstr """un <literal>UPDATE</literal> para crear el enlace desde <literal>p</literal> ""a <literal>c</literal>"#: index.docbook:95msgid """This is not only inefficient, but also violates any <literal>NOT NULL</""literal> constraint on the <literal>parent_id</literal> column. We can fix ""the nullability constraint violation by specifying <literal>not-null=\"true""\"</literal> in the collection mapping:"msgstr """Esto no es s&#x00f3;lo ineficiente, sino que adem&#x00e1;s viola cualquier ""restricci&#x00f3;n <literal>NOT NULL</literal> en la columna ""<literal>parent_id</literal>. Podemos reparar la violaci&#x00f3;n de ""restricci&#x00f3;n de nulabilidad especificando <literal>not-null=\"true\"</""literal> en el mapeo de la colecci&#x00f3;n:"#: index.docbook:101msgid """<![CDATA[<set name=\"children\">\n""    <key column=\"parent_id\" not-null=\"true\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr """<![CDATA[<set name=\"children\">\n""    <key column=\"parent_id\" not-null=\"true\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"#: index.docbook:103msgid "However, this is not the recommended solution."msgstr "Sin embargo, esta no es la soluci&#x00f3;n recomendada."#: index.docbook:106msgid """The underlying cause of this behaviour is that the link (the foreign key ""<literal>parent_id</literal>) from <literal>p</literal> to <literal>c</""literal> is not considered part of the state of the <literal>Child</literal> ""object and is therefore not created in the <literal>INSERT</literal>. So the ""solution is to make the link part of the <literal>Child</literal> mapping."msgstr """El caso subyacente de este comportamiento es que el enlace (la clave ""for&#x00e1;nea <literal>parent_id</literal>) de <literal>p</literal> a ""<literal>c</literal> no es considerado parte del estado del objeto ""<literal>Child</literal> y por lo tanto no es creada en el <literal>INSERT</""literal>. De modo que la soluci&#x00f3;n es hacer el enlace parte del mapeo ""del <literal>Child</literal>."#: index.docbook:113msgid """<![CDATA[<many-to-one name=\"parent\" column=\"parent_id\" not-null=\"true\"/"">]]>"msgstr """<![CDATA[<many-to-one name=\"parent\" column=\"parent_id\" not-null=\"true\"/"">]]>"#: index.docbook:115msgid """(We also need to add the <literal>parent</literal> property to the ""<literal>Child</literal> class.)"msgstr """(Necesitamos adem&#x00e1;s a&#x00f1;adir la propiedad <literal>parent</""literal> a la clase <literal>Child</literal>.)"#: index.docbook:119msgid """Now that the <literal>Child</literal> entity is managing the state of the ""link, we tell the collection not to update the link. We use the ""<literal>inverse</literal> attribute."msgstr """Ahora que la entidad <literal>Child</literal> est&#x00e1; gestionando el ""estado del enlace, le decimos a la colecci&#x00f3;n que no actualice el ""enlace. Usamos el atributo <literal>inverse</literal>."#: index.docbook:124msgid """<![CDATA[<set name=\"children\" inverse=\"true\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"msgstr """<![CDATA[<set name=\"children\" inverse=\"true\">\n""    <key column=\"parent_id\"/>\n""    <one-to-many class=\"Child\"/>\n""</set>]]>"#: index.docbook:126msgid "The following code would be used to add a new <literal>Child</literal>"msgstr """El siguiente c&#x00f3;digo podr&#x00ed;a ser usado para a&#x00f1;adir un ""nuevo <literal>Child</literal>"#: index.docbook:130msgid """<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n""Child c = new Child();\n""c.setParent(p);\n""p.getChildren().add(c);\n""session.save(c);\n""session.flush();]]>"msgstr """<![CDATA[Parent p = (Parent) session.load(Parent.class, pid);\n""Child c = new Child();\n""c.setParent(p);\n""p.getChildren().add(c);\n""session.save(c);\n""session.flush();]]>"#: index.docbook:132msgid "And now, only one SQL <literal>INSERT</literal> would be issued!"msgstr """Y ahora, &#x00a1;S&#x00f3;lo se publicar&#x00ed;a un <literal>INSERT</""literal> de SQL!"#: index.docbook:136msgid """To tighten things up a bit, we could create an <literal>addChild()</literal> ""method of <literal>Parent</literal>."msgstr """Para ajustar un poco m&#x00e1;s las cosas, podr&#x00ed;amos crear un ""m&#x00e9;todo <literal>addChild()</literal> en <literal>Parent</literal>."#: index.docbook:141msgid """<![CDATA[public void addChild(Child c) {\n"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -