📄 example_parentchild.po
字号:
#, 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><one-to-many></literal> ""association from <literal>Parent</literal> to <literal>Child</literal>. (The ""alternative approach is to declare the <literal>Child</literal> as a ""<literal><composite-element></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ísimas cosas que los usuarios nuevos intentan hacer ""con Hibernate es modelar una relación de tipo padre / hijo. Para esto ""hay dos enfoques diferentes. Por varias razones, el enfoque más ""conveniente, especialmente para usuarios nuevos, es modelar tanto ""<literal>Parent</literal> como <literal>Child</literal> como clases de ""entidad con una asociación <literal><one-to-many></literal> ""desde <literal>Parent</literal> a <literal>Child</literal>. (El enfoque ""alternativo es declarar el <literal>Child</literal> como un <literal><""composite-element></literal>.) Ahora, resulta que la semántica por ""defecto de una asociación uno a muchos (en Hibernate) es mucho menos ""cercana a la semántica usual de una relación padre / hijo que ""aquellas de un mapeo de elementos compuestos. Explicaremos cómo usar ""una <emphasis>asociación uno a muchos bidireccional con tratamiento ""en cascada</emphasis> para modelar una relación padre / hijo ""eficiente y elegantemente. ¡No es para nada difí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ógica de ""la entidad que las posee; nunca de las entidades contenidas. ¡Esta es ""una distinció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ñade un objeto desde / a una colección, se ""incrementa el número de versión del dueño de la ""colecció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ón es una instancia de un ""tipo de valor (por ejemplo, un elemento compuesto), ese objeta cesará ""de ser persistente y su estado será completamente quitado de la base ""de datos. Asimismo, añadir una instancia de tipo de valor a la ""colección causará 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ón (una ""asociación uno-a-muchos o muchos-a-muchos), no será borrado, ""por defecto. Este comportamiento es completamente consistente. ¡Un ""cambio en el estado interno de otra entidad no hace desaparecer la entidad ""asociada! Asimismo, añadir una entidad a una colecció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ñadir una entidad ""a una colecció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ón padre / hijo. donde la vida del hijo está 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><one-to-many></literal> ""association from <literal>Parent</literal> to <literal>Child</literal>."msgstr """Supón que empezamos con una asociación simple <literal><one-""to-many></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ásemos el siguiente có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í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ólo ineficiente, sino que además viola cualquier ""restricción <literal>NOT NULL</literal> en la columna ""<literal>parent_id</literal>. Podemos reparar la violación de ""restricción de nulabilidad especificando <literal>not-null=\"true\"</""literal> en el mapeo de la colecció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ó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á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ó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ás añ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á gestionando el ""estado del enlace, le decimos a la colecció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ódigo podría ser usado para añ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, ¡Sólo se publicarí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ás las cosas, podríamos crear un ""mé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 + -