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

📄 tutorial.po

📁 hibernate 开源框架的代码 jar包希望大家能喜欢
💻 PO
📖 第 1 页 / 共 5 页
字号:
#, 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 """O Hibernate é uma camada na sua aplicação na qual se conecta com a base de ""dados, para isso necessita de informação da conexão. As conexões são feitas ""através de um pool de conexão JDBC, na qual teremos que configurar. A ""distribuição do Hibernate contém diversas ferramentas de pooling da conexão ""JDBC de fonte aberta, mas iremos usar o pool de conexão interna para este ""tutorial. Note que você tem que copiar a biblioteca necessária em seu ""classpath e use configurações diferentes para pooling de conexão caso você ""deseje utilizar um software de pooling JDBC terceirizado para qualidade de ""produção."#. 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 """Para as configurações do Hibernate, nós podemos usar um arquivo simples ""<literal>hibernate.properties</literal>, um arquivo mais ligeiramente ""sofisticado <literal>hibernate.cfg.xml</literal> ou até mesmo uma instalação ""programática completa. A maioria dos usuários preferem utilizar o arquivo de ""configuração XML"#. Tag: programlisting#: tutorial.xml:273#, no-c-formatmsgid """<![CDATA[<?xml version='1.0' encoding='utf-8'?>\n""<!DOCTYPE hibernate-configuration PUBLIC\n""        \"-//Hibernate/Hibernate Configuration DTD 3.0//EN\"\n""        \"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd""\">\n""\n""<hibernate-configuration>\n""\n""    <session-factory>\n""\n""        <!-- Database connection settings -->\n""        <property name=\"connection.driver_class\">org.hsqldb.jdbcDriver</""property>\n""        <property name=\"connection.url\">jdbc:hsqldb:hsql://localhost</""property>\n""        <property name=\"connection.username\">sa</property>\n""        <property name=\"connection.password\"></property>\n""\n""        <!-- JDBC connection pool (use the built-in) -->\n""        <property name=\"connection.pool_size\">1</property>\n""\n""        <!-- SQL dialect -->\n""        <property name=\"dialect\">org.hibernate.dialect.HSQLDialect</""property>\n""\n""        <!-- Enable Hibernate's automatic session context management -->\n""        <property name=\"current_session_context_class\">thread</property>\n""\n""        <!-- Disable the second-level cache  -->\n""        <property name=\"cache.provider_class\">org.hibernate.cache.""NoCacheProvider</property>\n""\n""        <!-- Echo all executed SQL to stdout -->\n""        <property name=\"show_sql\">true</property>\n""\n""        <!-- Drop and re-create the database schema on startup -->\n""        <property name=\"hbm2ddl.auto\">create</property>\n""\n""        <mapping resource=\"events/Event.hbm.xml\"/>\n""\n""    </session-factory>\n""\n""</hibernate-configuration>]]>"msgstr ""#. Tag: para#: tutorial.xml:275#, no-c-formatmsgid """Note that this XML configuration uses a different DTD. We configure ""Hibernate's <literal>SessionFactory</literal> - a global factory responsible ""for a particular database. If you have several databases, use several ""<literal>&lt;session-factory&gt;</literal> configurations, usually in ""several configuration files (for easier startup)."msgstr """Note que esta configuração XML usa um diferente DTD. Nós configuraremos as ""<literal>SessionFactory</literal> do Hibernate – uma factory global ""responsável por uma base de dedados particular. Se você tiver diversas bases ""de dados, use diversas configurações <literal>&lt;session-factory&gt;</""literal>, geralmente em diversos arquivos de configuração (para uma partida ""mais fácil)."#. Tag: para#: tutorial.xml:283#, no-c-formatmsgid """The first four <literal>property</literal> elements contain the necessary ""configuration for the JDBC connection. The dialect <literal>property</""literal> element specifies the particular SQL variant Hibernate generates. ""Hibernate's automatic session management for persistence contexts will come ""in handy as you will soon see. The <literal>hbm2ddl.auto</literal> option ""turns on automatic generation of database schemas - directly into the ""database. This can of course also be turned off (by removing the config ""option) or redirected to a file with the help of the <literal>SchemaExport</""literal> Ant task. Finally, we add the mapping file(s) for persistent ""classes to the configuration."msgstr """As primeiras quatro <literal>propriedades</literal> do elemento contém a ""configuração necessária para a conexão ao JDBC. A propriedade ""<literal>propriedade</literal> dialect do elemento especifica a variante ""particular do SQL que o Hibernate gera. O gerenciamento automático de sessão ""do Hibernate para contextos de persistência estará disponível em breve. A ""opção <literal>hbm2ddl.auto</literal> habilita a geração automática de ""schemas da base de dados – diretamente na base de dados. Isto também pode ""ser naturalmente desligado (removendo a opção de configuração) ou ""redirecionando para um arquivo com ajuda do <literal>SchemaExport</literal> ""nas tarefas do Ant. Finalmente, iremos adicionar os arquivos das classes de ""persistência mapeadas na configuração."#. Tag: para#: tutorial.xml:296#, no-c-formatmsgid """Copy this file into the source directory, so it will end up in the root of ""the classpath. Hibernate automatically looks for a file called ""<literal>hibernate.cfg.xml</literal> in the root of the classpath, on ""startup."msgstr """Copie este arquivo no diretório fonte, assim isto irá terminar na raiz ""(root) do classpath. O Hibernate automaticamente procura por um arquivo ""chamado <literal>hibernate.cfg.xml</literal> na raiz do classpath, no ""startup."#. Tag: title#: tutorial.xml:305#, no-c-formatmsgid "Building with Ant"msgstr "Construindo com o Ant"#. Tag: para#: tutorial.xml:307#, no-c-formatmsgid """We'll now build the tutorial with Ant. You will need to have Ant installed - ""get it from the <ulink url=\"http://ant.apache.org/bindownload.cgi\">Ant ""download page</ulink>. How to install Ant will not be covered here. Please ""refer to the <ulink url=\"http://ant.apache.org/manual/index.html\">Ant ""manual</ulink>. After you have installed Ant, we can start to create the ""buildfile. It will be called <literal>build.xml</literal> and placed ""directly in the development directory."msgstr """Nos iremos, agora, construir o tutorial com Ant. Você ira precisar o Ant ""instalado – se encontra disponível <ulink url=\"http://ant.apache.org/""bindownload.cgi\">na página de download do Ant</ulink>. Como instalar o Ant, ""não será abordado aqui. Caso tenha alguma dúvida, por favor, vá ao <ulink ""url=\"http://ant.apache.org/manual/index.html\">Ant manual</ulink>. Depois ""que tiver instalado o Ant, podemos começar a criar o arquivo de construção ""<literal>build.xml</literal>. Este arquivo será chamado de <literal>build.""xml</literal> e posto diretamente no diretório de desenvolvimento."#. Tag: para#: tutorial.xml:316#, no-c-formatmsgid "A basic build file looks like this:"msgstr "Um arquivo básico de build, se parece com isto:"#. Tag: programlisting#: tutorial.xml:320#, no-c-formatmsgid """<![CDATA[<project name=\"hibernate-tutorial\" default=\"compile\">\n""\n""    <property name=\"sourcedir\" value=\"${basedir}/src\"/>\n""    <property name=\"targetdir\" value=\"${basedir}/bin\"/>\n""    <property name=\"librarydir\" value=\"${basedir}/lib\"/>\n""\n""    <path id=\"libraries\">\n""        <fileset dir=\"${librarydir}\">\n""            <include name=\"*.jar\"/>\n""        </fileset>\n""    </path>\n""\n""    <target name=\"clean\">\n""        <delete dir=\"${targetdir}\"/>\n""        <mkdir dir=\"${targetdir}\"/>\n""    </target>\n""\n""    <target name=\"compile\" depends=\"clean, copy-resources\">\n""      <javac srcdir=\"${sourcedir}\"\n""             destdir=\"${targetdir}\"\n""             classpathref=\"libraries\"/>\n""    </target>\n""\n""    <target name=\"copy-resources\">\n""        <copy todir=\"${targetdir}\">\n""            <fileset dir=\"${sourcedir}\">\n""                <exclude name=\"**/*.java\"/>\n""            </fileset>\n""        </copy>\n""    </target>\n""\n""</project>]]>"msgstr ""#. Tag: para#: tutorial.xml:322#, no-c-formatmsgid """This will tell Ant to add all files in the lib directory ending with ""<literal>.jar</literal> to the classpath used for compilation. It will also ""copy all non-Java source files to the target directory, e.g. configuration ""and Hibernate mapping files. If you now run Ant, you should get this output:"msgstr """Isto irá avisar ao Ant para adicionar todos os arquivos no diretório lib ""terminando com <literal>.jar</literal>, para o classpath usado para ""compilação. Irá também copiar todos os arquivos não-java para o diretório ""alvo (arquivos de configuração, mapeamento). Se você rodar o ant agora, ""deverá ter esta saída."#. Tag: programlisting#: tutorial.xml:329#, no-c-formatmsgid """<![CDATA[C:\\hibernateTutorial\\>ant\n""Buildfile: build.xml\n""\n""copy-resources:\n""     [copy] Copying 2 files to C:\\hibernateTutorial\\bin\n""\n""compile:\n""    [javac] Compiling 1 source file to C:\\hibernateTutorial\\bin\n""\n""BUILD SUCCESSFUL\n""Total time: 1 second ]]>"msgstr ""#. Tag: title#: tutorial.xml:334#, no-c-formatmsgid "Startup and helpers"msgstr "Startup and helpers"#. Tag: para#: tutorial.xml:336#, no-c-formatmsgid """It's time to load and store some <literal>Event</literal> objects, but first ""we have to complete the setup with some infrastructure code. We have to ""startup Hibernate. This startup includes building a global ""<literal>SessionFactory</literal> object and to store it somewhere for easy ""access in application code. A <literal>SessionFactory</literal> can open up ""new <literal>Session</literal>'s. A <literal>Session</literal> represents a ""single-threaded unit of work, the <literal>SessionFactory</literal> is a ""thread-safe global object, instantiated once."msgstr """É hora de carregar e arquivar alguns objetos <literal>Event</literal>, mas ""primeiro nós temos de completar o setup com algum código de infraestrutura. ""Este startup inclui a construção de um objeto <literal>SessionFactory</""literal> global e armazenar isto em algum lugar de fácil acesso para o ""código da aplicação. Uma <literal>SessionFactory</literal> pode abrir novas ""<literal>Session</literal>'s. Uma <literal>Session</literal> representa uma ""unidade single-theaded do trabalho, a <literal>SessionFactory</literal> é um ""objeto global thread-safe, instanciado uma vez."#. Tag: para#: tutorial.xml:346#, no-c-formatmsgid """We'll create a <literal>HibernateUtil</literal> helper class which takes ""care of startup and makes accessing a <literal>SessionFactory</literal> ""convenient. Let's have a look at the implementation:"msgstr """Nos iremos criar uma classe de ajuda <literal>HibernateUtil</literal>, que ""toma conta do startup e faz acesso a uma <literal>SessionFactory</literal> ""conveniente. Vamos dar uma olhada na implementação:"#. Tag: programlisting#: tutorial.xml:352#, no-c-formatmsgid """<![CDATA[package util;\n""\n""import org.hibernate.*;\n""import org.hibernate.cfg.*;\n""\n""public class HibernateUtil {\n""\n""    private static final SessionFactory sessionFactory;\n""\n""    static {\n""        try {\n""            // Create the SessionFactory from hibernate.cfg.xml\n""            sessionFactory = new Configuration().configure().""buildSessionFactory();\n""        } catch (Throwable ex) {\n""            // Make sure you log the exception, as it might be swallowed\n""            System.err.println(\"Initial SessionFactory creation failed.\" + ""ex);\n""            throw new ExceptionInInitializerError(ex);\n""        }\n""    }\n""\n""    public static SessionFactory getSessionFactory() {\n""        return sessionFactory;\n""    }\n""\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:354#, no-c-formatmsgid """This class does not only produce the global <literal>SessionFactory</""literal> in its static initializer (called once by the JVM when the class is ""loaded), but also hides the fact that it uses a static singleton. It might ""as well lookup the <literal>SessionFactory</literal> from JNDI in an ""application server."msgstr ""

⌨️ 快捷键说明

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