📄 tutorial.po
字号:
" \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\n""\n""<hibernate-mapping>\n""[...]\n""</hibernate-mapping>]]>"msgstr ""#. Tag: para#: tutorial.xml:132#, no-c-formatmsgid """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 """注意Hibernate的DTD是非常复杂的。你的编辑器或者IDE里使用它来自动完成那些用来映""射的XML元素(element)和属性(attribute)。你也可以在文本编辑器里打开DTD-这""是最简单的方式来概览所有的元素和attribute,并查看它们的缺省值以及注释。注意""Hibernate不会从web加载DTD文件,但它会首先在应用程序的classpath中查找。DTD文件""已包括在<literal>hibernate3.jar</literal>里,同时也在Hibernate发布包的""<literal>src/</literal>目录下。"#. Tag: para#: tutorial.xml:143#, no-c-formatmsgid """We will omit the DTD declaration in future examples to shorten the code. It ""is of course not optional."msgstr """为缩短代码长度,在以后的例子里我们会省略DTD的声明。当然,在实际的应用程序中,""DTD声明是必须的。"#. Tag: para#: tutorial.xml:148#, no-c-formatmsgid """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 """在<literal>hibernate-mapping</literal>标签(tag)之间, 含有一个""<literal>class</literal>元素。所有的持久化实体类(再次声明,或许接下来会有依""赖类,就是那些次要的实体)都需要一个这样的映射,来把类对象映射到SQL数据库里的""表。"#. Tag: programlisting#: tutorial.xml:155#, no-c-formatmsgid """<![CDATA[<hibernate-mapping>\n""\n"" <class name=\"events.Event\" table=\"EVENTS\">\n""\n"" </class>\n""\n""</hibernate-mapping>]]>"msgstr ""#. Tag: para#: tutorial.xml:157#, no-c-formatmsgid """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 """到目前为止,我们告诉了Hibernate怎样把<literal>Events</literal>类的对象持久化""到数据库的<literal>EVENTS</literal>表里,以及怎样从<literal>EVENTS</literal>""表加载到<literal>Events</literal>类的对象。每个实例对应着数据库表中的一行。现""在我们将继续讨论有关唯一标识符属性到数据库表的映射。另外,由于我们不关心怎样""处理这个标识符,我们就配置由Hibernate的标识符生成策略来产生代理主键字段。"#. Tag: programlisting#: tutorial.xml:165#, no-c-formatmsgid """<![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 ""#. Tag: para#: tutorial.xml:167#, no-c-formatmsgid """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 """<literal>id</literal>元素是标识符属性的声明,<literal>name=\"id\"</literal> ""声明了Java属性的名字 - Hibernate会使用<literal>getId()</literal>和""<literal>setId()</literal>来访问它。 <literal>column</literal>属性则告诉""Hibernate, 我们使用<literal>EVENTS</literal>表的哪个字段作为主键。嵌套的""<literal>generator</literal>元素指定了标识符生成策略,在这里我们指定""<literal>native</literal>,它根据已配置的数据库(方言)自动选择最佳的标识符生""成策略。Hibernate支持由数据库生成,全局唯一性(globally unique)和应用程序指""定(或者你自己为任何已有策略所写的扩展)这些策略来生成标识符。"#. Tag: para#: tutorial.xml:180#, no-c-formatmsgid """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 """最后我们在映射文件里面包含需要持久化属性的声明。默认情况下,类里面的属性都被""视为非持久化的:"#. Tag: programlisting#: tutorial.xml:186#, no-c-formatmsgid """<![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 ""#. Tag: para#: tutorial.xml:188#, no-c-formatmsgid """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 """和<literal>id</literal>元素一样,<literal>property</literal>元素的""<literal>name</literal>属性告诉Hibernate使用哪个getter和setter方法。在此例""中,Hibernate会寻找<literal>getDate()/setDate()</literal>, 以及""<literal>getTitle()/setTitle()</literal>。"#. Tag: para#: tutorial.xml:195#, no-c-formatmsgid """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 """为什么<literal>date</literal>属性的映射含有<literal>column</literal> ""attribute,而<literal>title</literal>却没有?当没有设定<literal>column</""literal> attribute 的时候,Hibernate缺省地使用JavaBean的属性名作为字段名。对""于<literal>title</literal>,这样工作得很好。然而,<literal>date</literal>在多""数的数据库里,是一个保留关键字,所以我们最好把它映射成一个不同的名字。"#. Tag: para#: tutorial.xml:204#, no-c-formatmsgid """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 """另一有趣的事情是<literal>title</literal>属性缺少一个<literal>type</literal> ""attribute。我们在映射文件里声明并使用的类型,却不是我们期望的那样,是Java数据""类型,同时也不是SQL数据库的数据类型。这些类型就是所谓的Hibernate 映射类型""<emphasis>(mapping types)</emphasis>,它们能把Java数据类型转换到SQL数据类""型,反之亦然。再次重申,如果在映射文件中没有设置<literal>type</literal>属性的""话,Hibernate会自己试着去确定正确的转换类型和它的映射类型。在某些情况下这个自""动检测机制(在Java 类上使用反射机制)不会产生你所期待或需要的缺省值。""<literal>date</literal>属性就是个很好的例子,Hibernate无法知道这个属性""(<literal>java.util.Date</literal>类型的)应该被映射成:SQL <literal>date</""literal>,或<literal>timestamp</literal>,还是<literal>time</literal> 字段。""在此例中,把这个属性映射成<literal>timestamp</literal> 转换器,这样我们预留了""日期和时间的全部信息。"#. Tag: para#: tutorial.xml:220#, no-c-formatmsgid """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 """应该把这个映射文件保存为<literal>Event.hbm.xml</literal>,且就在""<literal>Event</literal>Java类的源文件目录下。映射文件可随意地命名,但""<literal>hbm.xml</literal>的后缀已成为Hibernate开发者社区的约定。现在目录结构""看起来应该像这样:"#. Tag: programlisting#: tutorial.xml:228#, no-c-formatmsgid """<![CDATA[.\n""+lib\n"" <Hibernate and third-party libraries>\n""+src\n"" +events\n"" Event.java\n"" Event.hbm.xml]]>"msgstr ""#. Tag: para#: tutorial.xml:230#, no-c-formatmsgid "We continue with the main configuration of Hibernate."msgstr "我们继续进行Hibernate的主要配置。"#. Tag: title#: tutorial.xml:237#, no-c-formatmsgid "Hibernate configuration"msgstr "Hibernate配置"#. Tag: para#: tutorial.xml:239#, no-c-formatmsgid """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."msgstr """现在我们已经有了一个持久化类和它的映射文件,该是配置Hibernate的时候了。在此之""前,我们需要一个数据库。 HSQL DB是种基于Java 的SQL数据库管理系统(DBMS),可""以从HSQL DB的网站上下载。实际上,你只需下载的包中的<literal>hsqldb.jar</""literal>文件,并把这个文件放在开发文件夹的<literal>lib/</literal>目录下即可。"#. Tag: para#: tutorial.xml:247#, no-c-formatmsgid """Create a directory called <literal>data</literal> in the root of the ""development directory - this is where HSQL DB will store its data files. Now ""start the database by running <literal>java -classpath ../lib/hsqldb.jar org.""hsqldb.Server</literal> in this data directory. You can see it start up and ""bind to a TCP/IP socket, this is where our application will connect later. ""If you want to start with a fresh database during this tutorial, shutdown ""HSQL DB (press <literal>CTRL + C</literal> in the window), delete all files ""in the <literal>data/</literal> directory, and start HSQL DB again."msgstr """在开发的根目录下创建一个<literal>data</literal>目录 - 这是HSQL DB存储数据文""件的地方。此时在data目录中运行<literal>java -classpath ../lib/hsqldb.jar org.""hsqldb.Server</literal>就可启动数据库。你可以在log中看到它的启动,及绑定到""TCP/IP套结字,这正是我们的应用程序稍后会连接的地方。如果你希望在本例中运行一""个全新的数据库,就在窗口中按下<literal>CTRL + C</literal>来关闭HSQL数据库,并""删除<literal>data/</literal>目录下的所有文件,再重新启动HSQL数据库。"#. Tag: para#: tutorial.xml:257#, no-c-formatmsgid """Hibernate is the layer in your application which connects to this database, ""so it needs connection information. The connections are made through a JDBC ""connection pool, which we also have to configure. The Hibernate distribution ""contains several open source JDBC connection pooling tools, but will use the ""Hibernate built-in connection pool for this tutorial. Note that you have to ""copy the required library into your classpath and use different connection ""pooling settings if you want to use a production-quality third party JDBC ""pooling software."msgstr """Hibernate是你的应用程序里连接数据库的那层,所以它需要连接用的信息。连接""(connection)是通过一个也由我们配置的JDBC连接池(connection pool)来完成的。""Hibernate的发布包里包含了许多开源的(open source)连接池,但在我们例子中使用""Hibernate内置的连接池。注意,如果你希望使用一个产品级(production-quality)的第""三方连接池软件,你必须拷贝所需的库文件到你的classpath下,并使用不同的连接池设""置。"#. Tag: para#: tutorial.xml:267#, no-c-formatmsgid """For Hibernate's configuration, we can use a simple <literal>hibernate.""properties</literal> file, a slightly more sophisticated <literal>hibernate.""cfg.xml</literal> file, or even complete programmatic setup. Most users ""prefer the XML configuration file:"msgstr ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -