📄 tutorial.po
字号:
msgstr "El fichero de mapeo"#: index.docbook:119msgid """Hibernate needs to know how to load and store objects of the persistent ""class. This is where the Hibernate mapping file comes into play. The mapping ""file tells Hibernate what table in the database it has to access, and what ""columns in that table it should use."msgstr """Hibernate necesita saber cómo cargar y almacenar objetos de la clase ""persistente. Aquí es donde el fichero de mapeo de Hibernate entra en ""juego. El fichero de mapeo le dice a Hibernate a qué tabla en la base ""de datos tiene que acceder, y qué columnas en esta tabla debe usar."#: index.docbook:126msgid "The basic structure of a mapping file looks like this:"msgstr "La estructura básica de un fichero de mapeo se parece a esto:"#: index.docbook:130msgid """<![CDATA[<?xml version=\"1.0\"?>\n""<!DOCTYPE hibernate-mapping PUBLIC\n"" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n"" \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\n""\n""<hibernate-mapping>\n""[...]\n""</hibernate-mapping>]]>"msgstr """<![CDATA[<?xml version=\"1.0\"?>\n""<!DOCTYPE hibernate-mapping PUBLIC\n"" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n"" \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\n""\n""<hibernate-mapping>\n""[...]\n""</hibernate-mapping>]]>"#: index.docbook:132msgid """Note that the Hibernate DTD is very sophisticated. You can use it for auto-""completion of XML mapping elements and attributes in your editor or IDE. You ""also should open up the DTD file in your text editor - it's the easiest way ""to get an overview of all elements and attributes and to see the defaults, ""as well as some comments. Note that Hibernate will not load the DTD file ""from the web, but first look it up from the classpath of the application. ""The DTD file is included in <literal>hibernate3.jar</literal> as well as in ""the <literal>src/</literal> directory of the Hibernate distribution."msgstr """Observa que el DTD de Hibernate es muy sofisticado. Puedes usarlo para ""autocompleción de los elementos y atributos XML de mapeo en tu editor ""o IDE. Debes también abrir el fichero DTD en tu editor de texto. Es ""la forma más fácil para tener un panorama de todos los ""elementos y atributos y ver los valores por defectos, así como ""algunos comentarios. Nota que Hibernate no cargará el fichero DTD de ""la web, sino que primero buscará en el classpath de la ""aplicación. El fichero DTD está incluído en ""<literal>hibernate3.jar</literal> así como también en el ""directorio <literal>src/</literal> de la distribución de Hibernate."#: index.docbook:143msgid """We will omit the DTD declaration in future examples to shorten the code. It ""is of course not optional."msgstr """Omitiremos la declaración de DTD en futuros ejemplos para acortar el ""código. Por supuesto, no es opcional."#: index.docbook:148msgid """Between the two <literal>hibernate-mapping</literal> tags, include a ""<literal>class</literal> element. All persistent entity classes (again, ""there might be dependent classes later on, which are not first-class ""entities) need such a mapping, to a table in the SQL database:"msgstr """Entre las dos etiquetas <literal>hibernate-mapping</literal>, incluye un ""elemento <literal>class</literal>. Todas las clases de entidad persistentes ""(de nuevo, podría haber más adelante clases dependientes, que ""no sean entidades de-primera-clase) necesitan dicho mapeo a una tabla en la ""base de datos SQL:"#: index.docbook:155msgid """<![CDATA[<hibernate-mapping>\n""\n"" <class name=\"events.Event\" table=\"EVENTS\">\n""\n"" </class>\n""\n""</hibernate-mapping>]]>"msgstr """<![CDATA[<hibernate-mapping>\n""\n"" <class name=\"Event\" table=\"EVENTS\">\n""\n"" </class>\n""\n""</hibernate-mapping>]]>"#: index.docbook:157msgid """So far we told Hibernate how to persist and load object of class ""<literal>Event</literal> to the table <literal>EVENTS</literal>, each ""instance represented by a row in that table. Now we continue with a mapping ""of the unique identifier property to the tables primary key. In addition, as ""we don't want to care about handling this identifier, we configure ""Hibernate's identifier generation strategy for a surrogate primary key ""column:"msgstr """Hasta ahora dijimos a Hibernate cómo persistir y cargar el objeto de ""clase <literal>Event</literal> a la tabla <literal>EVENTS</literal>, cada ""instancia representada por una fila en esta tabla. Ahora continuamos con un ""mapeo de la propiedad de identificado único a la clave primaria de la ""tabla. Además, como no queremos cuidar del manejo de este ""identificador, configuramos la estrategia de generación de ""identificadores para una columna clave primaria delegada:"#: index.docbook:165msgid """<![CDATA[<hibernate-mapping>\n""\n"" <class name=\"events.Event\" table=\"EVENTS\">\n"" <id name=\"id\" column=\"EVENT_ID\">\n"" <generator class=\"native\"/>\n"" </id>\n"" </class>\n""\n""</hibernate-mapping>]]>"msgstr """<![CDATA[<hibernate-mapping>\n""\n"" <class name=\"Event\" table=\"EVENTS\">\n"" <id name=\"id\" column=\"EVENT_ID\">\n"" <generator class=\"increment\"/>\n"" </id>\n"" </class>\n""\n""</hibernate-mapping>]]>"#: index.docbook:167msgid """The <literal>id</literal> element is the declaration of the identifer ""property, <literal>name=\"id\"</literal> declares the name of the Java ""property - Hibernate will use the getter and setter methods to access the ""property. The column attribute tells Hibernate which column of the ""<literal>EVENTS</literal> table we use for this primary key. The nested ""<literal>generator</literal> element specifies the identifier generation ""strategy, in this case we used <literal>native</literal>, which picks the ""best strategy depending on the configured database (dialect). Hibernate ""supports database generated, globally unique, as well as application ""assigned identifiers (or any strategy you have written an extension for)."msgstr """El elemento <literal>id</literal> el la declaración de la propiedad ""identificadora, <literal>name=\"id\"</literal> declara el nombre de la ""propiedad Java. Hibernate usará los métodos getter y setter ""para acceder a la propiedad. El attributo de columna dice a Hibernate ""cuál columna de la tabla <literal>EVENTS</literal> usamos para esta ""clave primaria. El elemento anidado <literal>generator</literal> especifica ""la estrategia de generación de identificadores, en este caso usamos ""<literal>increment</literal>, que es un método muy simple de ""incremento de número en-memoria útil mayormente para testeo (y ""tutoriales). Hibernate también soporta identificadores generados por ""base de datos, globalmente únicos, así como también ""asignados por aplicación (o cualquier estrategia para la que hayas ""escrito una extensión)."#: index.docbook:180msgid """Finally we include declarations for the persistent properties of the class ""in the mapping file. By default, no properties of the class are considered ""persistent:"msgstr """Finalmente incluímos declaraciones para las propiedades persistentes ""de la clases en el fichero de mapeo. Por defecto, ninguna propiedad de la ""clase se considera persistente:"#: index.docbook:186msgid """<![CDATA[\n""<hibernate-mapping>\n""\n"" <class name=\"events.Event\" table=\"EVENTS\">\n"" <id name=\"id\" column=\"EVENT_ID\">\n"" <generator class=\"native\"/>\n"" </id>\n"" <property name=\"date\" type=\"timestamp\" column=\"EVENT_DATE\"/>\n"" <property name=\"title\"/>\n"" </class>\n""\n""</hibernate-mapping>]]>"msgstr """<![CDATA[\n""<hibernate-mapping>\n""\n"" <class name=\"Event\" table=\"EVENTS\">\n"" <id name=\"id\" column=\"EVENT_ID\">\n"" <generator class=\"increment\"/>\n"" </id>\n"" <property name=\"date\" type=\"timestamp\" column=\"EVENT_DATE\"/>\n"" <property name=\"title\"/>\n"" </class>\n""\n""</hibernate-mapping>]]>"#: index.docbook:188msgid """Just as with the <literal>id</literal> element, the <literal>name</literal> ""attribute of the <literal>property</literal> element tells Hibernate which ""getter and setter methods to use. So, in this case, Hibernate will look for ""<literal>getDate()/setDate()</literal>, as well as <literal>getTitle()/""setTitle()</literal>."msgstr """Al igual que con el elemento <literal>id</literal>, el atributo ""<literal>name</literal> del elemento <literal>property</literal> dice a ""Hibernate cáles métodos getter y setter usar."#: index.docbook:195msgid """Why does the <literal>date</literal> property mapping include the ""<literal>column</literal> attribute, but the <literal>title</literal> ""doesn't? Without the <literal>column</literal> attribute Hibernate by ""default uses the property name as the column name. This works fine for ""<literal>title</literal>. However, <literal>date</literal> is a reserved ""keyword in most database, so we better map it to a different name."msgstr """¿Por qué el mapeo de la propiedad <literal>date</literal> incluye el ""atributo <literal>column</literal>, pero el de la de <literal>title</""literal> no? Sin el atributo <literal>column</literal> Hibernate usa por ""defecto el nombre de propiedad como nombre de columna. Esto funciona bien ""para <literal>title</literal>. Sin embargo, However, <literal>date</literal> ""es una palabra reservada en la mayoría de las bases de datos, ""así que mejor la mapeamos a un nombre diferente."#: index.docbook:204msgid """The next interesting thing is that the <literal>title</literal> mapping also ""lacks a <literal>type</literal> attribute. The types we declare and use in ""the mapping files are not, as you might expect, Java data types. They are ""also not SQL database types. These types are so called <emphasis>Hibernate ""mapping types</emphasis>, converters which can translate from Java to SQL ""data types and vice versa. Again, Hibernate will try to determine the ""correct conversion and mapping type itself if the <literal>type</literal> ""attribute is not present in the mapping. In some cases this automatic ""detection (using Reflection on the Java class) might not have the default ""you expect or need. This is the case with the <literal>date</literal> ""property. Hibernate can't know if the property (which is of <literal>java.""util.Date</literal>) should map to a SQL <literal>date</literal>, ""<literal>timestamp</literal>, or <literal>time</literal> column. We preserve ""full date and time information by mapping the property with a ""<literal>timestamp</literal> converter."msgstr """La próxima cosa interesante es que el mapeo de <literal>title</""literal> carece de un atributo <literal>type</literal>. Los tipos que ""declaramos y usamos en el fichero de mapeo no son, como podrías ""esperar, tipos de datos Java. Tampoco son tipos de base de datos SQL. Estos ""tipos son los llamados así <emphasis>Tipos de mapeo de Hibernate</""emphasis>, convertidores que pueden traducir de tipos Java a SQL y vice ""versa. De nuevo, Hibernate intentará determinar la conversión ""y el mapeo mismo de tipo correctos si el atributo <literal>type</literal> no ""estuviese presente en el mapeo. En algunos casos esta detección ""automática (usando reflección en la clase Java) puede no tener ""lo que esperas o necesitas. Este es el caso de la propiedad <literal>date</""literal>. Hibernate no puede saber is la propiedad mapeará a una ""columna <literal>date</literal>, <literal>timestamp</literal> o ""<literal>time</literal>. Declaramos que queremos preservar la ""información completa de fecha y hora mapeando la propiedad con un ""<literal>timestamp</literal>."#: index.docbook:220msgid """This mapping file should be saved as <literal>Event.hbm.xml</literal>, right ""in the directory next to the <literal>Event</literal> Java class source ""file. The naming of mapping files can be arbitrary, however the <literal>hbm.""xml</literal> suffix is a convention in the Hibernate developer community. ""The directory structure should now look like this:"msgstr """Este fichero de mapeo debe ser salvado como <literal>Event.hbm.xml</""literal>, justo en el directorio próximo al fichero de código ""fuente de la clase Java <literal>Event</literal>. El nombrado de los ""ficheros de mapeo puede ser arbitrario, sin embargo, el sufijo <literal>hbm.""xml</literal> se ha vuelto una convención el la comunidad de ""desarrolladores de Hibernate. La estructura de directorio debe ahora verse ""como esto:"#: index.docbook:228msgid """<![CDATA[.\n""+lib\n"" <Hibernate and third-party libraries>\n""+src\n"" +events\n"" Event.java\n"" Event.hbm.xml]]>"msgstr """<![CDATA[.\n""+lib\n"" <Hibernate and third-party libraries>\n""+src\n"" Event.java\n"" Event.hbm.xml]]>"#: index.docbook:230msgid "We continue with the main configuration of Hibernate."msgstr "Continuamos con la configuración principal de Hibernate."#: index.docbook:237msgid "Hibernate configuration"msgstr "Configuración de Hibernate"#: index.docbook:239msgid """We now have a persistent class and its mapping file in place. It is time to ""configure Hibernate. Before we do this, we will need a database. HSQL DB, a ""java-based SQL DBMS, can be downloaded from the HSQL DB website(http://""hsqldb.org/). Actually, you only need the <literal>hsqldb.jar</literal> from ""this download. Place this file in the <literal>lib/</literal> directory of ""the development folder."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -