📄 tutorial.po
字号:
"Esta classe não só produz a global <literal>SessionFactory</literal> no seu ""static initializer (chamado uma vez pela JVM quando a classe é carregada), ""mas também esconde o fato de que isto usa um static singleton. Ela pode ""muito bem, enxergar a <literal>SessionFactory</literal> do JNDI em um ""application server."#. Tag: para#: tutorial.xml:361#, no-c-formatmsgid """If you give the <literal>SessionFactory</literal> a name in your ""configuration file, Hibernate will in fact try to bind it to JNDI after it ""has been built. To avoid this code completely you could also use JMX ""deployment and let the JMX-capable container instantiate and bind a ""<literal>HibernateService</literal> to JNDI. These advanced options are ""discussed in the Hibernate reference documentation."msgstr """Se você der à <literal>SessionFactory</literal> um nome, no seu arquivo de ""configuração. O Hibernate irá, de fato, tentar uni-lo ao JNDI depois que ""estiver construído. Para evitar este completamente este código, você também ""poderia usar JMX deployment e deixar o contêiner JMX capaz, instanciar e ""unir um <literal>HibernateService</literal> no JNDI. Essas opções avançadas ""são discutidas no documento de referência do Hibernate."#. Tag: para#: tutorial.xml:370#, no-c-formatmsgid """Place <literal>HibernateUtil.java</literal> in the development source ""directory, in a package next to <literal>events</literal>:"msgstr """Coloque o <literal>HibernateUtil.java</literal> no diretório de arquivos de ""desenvolvimento(source), em um pacote após o <literal>events</literal>:"#. Tag: programlisting#: tutorial.xml:375#, no-c-formatmsgid """<![CDATA[.\n""+lib\n"" <Hibernate and third-party libraries>\n""+src\n"" +events\n"" Event.java\n"" Event.hbm.xml\n"" +util\n"" HibernateUtil.java\n"" hibernate.cfg.xml\n""+data\n""build.xml]]>"msgstr ""#. Tag: para#: tutorial.xml:377#, no-c-formatmsgid """This should again compile without problems. We finally need to configure a ""logging system - Hibernate uses commons logging and leaves you the choice ""between Log4j and JDK 1.4 logging. Most developers prefer Log4j: copy ""<literal>log4j.properties</literal> from the Hibernate distribution (it's in ""the <literal>etc/</literal> directory) to your <literal>src</literal> ""directory, next to <literal>hibernate.cfg.xml</literal>. Have a look at the ""example configuration and change the settings if you like to have more ""verbose output. By default, only Hibernate startup message are shown on ""stdout."msgstr """Novamente, isto deve compilar sem problemas. Finalmente, nós precisamos ""configurar um sistema de logging – o Hibernate usa commons logging e deixa ""você escolher entre o Log4j e o logging do JDK 1.4 . A maioria dos ""desenvolvedores preferem o Log4j: copie <literal>log4j.properties</literal> ""da distribuição do Hibernate (está no diretório <literal>etc/</literal>), ""para seu diretório <literal>src</literal>, depois vá em hibernate.cfg.xml. ""Dê uma olhada no exemplo de configuração e mude as configurações se você ""quizer ter uma saída mais detalhada. Por default, apenas as mensagems de ""startup e shwwn do Hibernate é mostrada no stdout."#. Tag: para#: tutorial.xml:387#, no-c-formatmsgid """The tutorial infrastructure is complete - and we are ready to do some real ""work with Hibernate."msgstr """O tutorial de infra-estrutura está completo - e nós já estamos preparados ""para algum trabalho de verdade com o Hibernate."#. Tag: title#: tutorial.xml:395#, no-c-formatmsgid "Loading and storing objects"msgstr "Carregando e salvando objetos"#. Tag: para#: tutorial.xml:397#, no-c-formatmsgid """Finally, we can use Hibernate to load and store objects. We write an ""<literal>EventManager</literal> class with a <literal>main()</literal> ""method:"msgstr """Finalmente, nós podemos usar o Hibernate para carregar e armazenar objetos. ""Nós escrevemos uma classe <literal>EventManager</literal> com um método main""():"#. Tag: programlisting#: tutorial.xml:402#, no-c-formatmsgid """<![CDATA[package events;\n""import org.hibernate.Session;\n""\n""import java.util.Date;\n""\n""import util.HibernateUtil;\n""\n""public class EventManager {\n""\n"" public static void main(String[] args) {\n"" EventManager mgr = new EventManager();\n""\n"" if (args[0].equals(\"store\")) {\n"" mgr.createAndStoreEvent(\"My Event\", new Date());\n"" }\n""\n"" HibernateUtil.getSessionFactory().close();\n"" }\n""\n"" private void createAndStoreEvent(String title, Date theDate) {\n""\n"" Session session = HibernateUtil.getSessionFactory().getCurrentSession""();\n""\n"" session.beginTransaction();\n""\n"" Event theEvent = new Event();\n"" theEvent.setTitle(title);\n"" theEvent.setDate(theDate);\n""\n"" session.save(theEvent);\n""\n"" session.getTransaction().commit();\n"" }\n""\n""}]]>"msgstr ""#. Tag: para#: tutorial.xml:404#, no-c-formatmsgid """We create a new <literal>Event</literal> object, and hand it over to ""Hibernate. Hibernate now takes care of the SQL and executes <literal>INSERT</""literal>s on the database. Let's have a look at the <literal>Session</""literal> and <literal>Transaction</literal>-handling code before we run this."msgstr """Nós criamos um novo objeto <literal>Event</literal>, e passamos para o ""Hibernate. O Hibernate sabe como tomar conta do SQL e executa ""<literal>INSERT</literal>s no banco de dados. Vamos dar uma olhada na ""<literal>Session</literal> e no código <literal>Transaction</literal>-""handling antes de executarmos."#. Tag: para#: tutorial.xml:411#, no-c-formatmsgid """A <literal>Session</literal> is a single unit of work. For now we'll keep ""things simple and assume a one-to-one granularity between a Hibernate ""<literal>Session</literal> and a database transaction. To shield our code ""from the actual underlying transaction system (in this case plain JDBC, but ""it could also run with JTA) we use the <literal>Transaction</literal> API ""that is available on the Hibernate <literal>Session</literal>."msgstr """Um <literal>Session</literal> é uma unidade simples de trabalho. Por agora ""nós iremos pegar coisas simples e assumir uma granularidade de um-pra-um ""entre uma <literal>Session</literal> do Hibernate e uma transação de banco ""de dados. Para proteger nosso código de um atual sistema subjacente de ""transação (nesse caso puro JDBC, mas também poderia rodar com JTA), nos ""usamos a API <literal>Transaction</literal>, que está disponível na ""<literal>Session</literal> do Hibernate."#. Tag: para#: tutorial.xml:419#, no-c-formatmsgid """What does <literal>sessionFactory.getCurrentSession()</literal> do? First, ""you can call it as many times and anywhere you like, once you get hold of ""your <literal>SessionFactory</literal> (easy thanks to ""<literal>HibernateUtil</literal>). The <literal>getCurrentSession()</""literal> method always returns the \"current\" unit of work. Remember that ""we switched the configuration option for this mechanism to \"thread\" in ""<literal>hibernate.cfg.xml</literal>? Hence, the current unit of work is ""bound to the current Java thread that executes our application. However, ""this is not the full picture, you also have to consider scope, when a unit ""of work begins and when it ends."msgstr """O que a <literal>sessionFactory.getCurrentSession()</literal> faz? Primeiro, ""você pode chamar quantas vezes e de onde quiser, uma vez você recebe sua ""<literal>SessionFactory</literal> (fácil graças ao <literal>HibernateUtil</""literal>). O método <literal>getCurrentSession()</literal> sempre retorna a ""unidade de trabalho \"corrente\". Lembra de que nós mudamos a opção de ""configuração desse mecanismo para thread no <literal>hibernate.cfg.xml</""literal>? Daqui em diante, o escopo da unidade de trabalho corrente é a ""thread Java corrente que executa nossa aplicação. Entretanto, esta não é ""toda a verdade. Uma"#. Tag: para#: tutorial.xml:430#, no-c-formatmsgid """A <literal>Session</literal> begins when it is first needed, when the first ""call to <literal>getCurrentSession()</literal> is made. It is then bound by ""Hibernate to the current thread. When the transaction ends, either through ""commit or rollback, Hibernate automatically unbinds the <literal>Session</""literal> from the thread and closes it for you. If you call ""<literal>getCurrentSession()</literal> again, you get a new ""<literal>Session</literal> and can start a new unit of work. This ""<emphasis>thread-bound</emphasis> programming model is the most popular way ""of using Hibernate, as it allows flexible layering of your code (transaction ""demarcation code can be separated from data access code, we'll do this later ""in this tutorial)."msgstr """<literal>Session</literal> começa quando é primeiramente necessária, quando ""é feita a primeira chamada à <literal>getCurrentSession()</literal>. É então ""limitado pelo Hibernate para thread corrente. Quando a transação termina, ""tanto com commit quanto rollback, o Hibernate também desune a ""<literal>Session</literal> da thread e fecha isso pra você. Se você chamar ""<literal>getCurrentSession()</literal> novamente, você receberá uma nova ""<literal>Session</literal> e pode começar uma nova unidade de trabalho. Esse ""modelo de programação de limite de thread <emphasis>thread-bound</emphasis>, ""é o modo mais popular de se usar o Hibernate."#. Tag: para#: tutorial.xml:441#, no-c-formatmsgid """Related to the unit of work scope, should the Hibernate <literal>Session</""literal> be used to execute one or several database operations? The above ""example uses one <literal>Session</literal> for one operation. This is pure ""coincidence, the example is just not complex enough to show any other ""approach. The scope of a Hibernate <literal>Session</literal> is flexible ""but you should never design your application to use a new Hibernate ""<literal>Session</literal> for <emphasis>every</emphasis> database ""operation. So even if you see it a few more times in the following (very ""trivial) examples, consider <emphasis>session-per-operation</emphasis> an ""anti-pattern. A real (web) application is shown later in this tutorial."msgstr """Related to the unit of work scope, should the Hibernate <literal>Session</""literal> be used to execute one or several database operations? The above ""example uses one <literal>Session</literal> for one operation. This is pure ""coincidence, the example is just not complex enough to show any other ""approach. The scope of a Hibernate <literal>Session</literal> is flexible ""but you should never design your application to use a new Hibernate ""<literal>Session</literal> for <emphasis>every</emphasis> database ""operation. So even if you see it a few more times in the following (very ""trivial) examples, consider <emphasis>session-per-operation</emphasis> an ""anti-pattern. A real (web) application is shown later in this tutorial."#. Tag: para#: tutorial.xml:452#, no-c-formatmsgid """Have a look at <xref linkend=\"transactions\"/> for more information about ""transaction handling and demarcation. We also skipped any error handling and ""rollback in the previous example."msgstr """Dê uma olhada no <xref linkend=\"transactions\"/> para mais informações a ""respeito de manipulação de transação e demarcação. Nós também pulamos ""qualquer manipulação de erro e rollback no exemplo anterior."#. Tag: para#: tutorial.xml:458#, no-c-formatmsgid """To run this first routine we have to add a callable target to the Ant build ""file:"msgstr """Para executar esta primeira rotina, nos teremos que adicionar um ponto de ""chamada para o arquivo de build do Ant:"#. Tag: programlisting#: tutorial.xml:462#, no-c-formatmsgid """<![CDATA[<target name=\"run\" depends=\"compile\">\n"" <java fork=\"true\" classname=\"events.EventManager\" classpathref=""\"libraries\">\n"" <classpath path=\"${targetdir}\"/>\n"" <arg value=\"${action}\"/>\n"" </java>\n""</target>]]>"msgstr ""#. Tag: para#: tutorial.xml:464#, no-c-formatmsgid """The value of the <literal>action</literal> argument is set on the command ""line when calling the target:"msgstr """O valor do argumento <literal>action</literal>, é setado na linha de comando ""quando chamando esse ponto:"#. Tag: programlisting#: tutorial.xml:469#, no-c-formatmsgid "<![CDATA[C:\\hibernateTutorial\\>ant run -Daction=store]]>"msgstr ""#. Tag: para#: tutorial.xml:471#, no-c-formatmsgid """You should see, after compilation, Hibernate starting up and, depending on ""your configuration, lots of log output. At the end you will find the ""following line:"msgstr """Você deverá ver, após a compilação, o startup do Hibernate e, dependendo da ""sua configuração, muito log de saída. No final você verá a seguinte linha:"#. Tag: programlisting#: tutorial.xml:476#, no-c-formatmsgid """<![CDATA[[java] Hibernate: insert into EVENTS (EVENT_DATE, title, EVENT_ID) ""values (?, ?, ?)]]>"msgstr ""#. Tag: para#: tutorial.xml:478
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -