📄 transactions.po
字号:
#, no-c-formatmsgid """<![CDATA[// Non-managed environment idiom\n""Session sess = factory.openSession();\n""Transaction tx = null;\n""try {\n"" tx = sess.beginTransaction();\n""\n"" // do some work\n"" ...\n""\n"" tx.commit();\n""}\n""catch (RuntimeException e) {\n"" if (tx != null) tx.rollback();\n"" throw e; // or display error message\n""}\n""finally {\n"" sess.close();\n""}]]>"msgstr ""#. Tag: para#: transactions.xml:424#, no-c-formatmsgid """You don't have to <literal>flush()</literal> the <literal>Session</literal> ""explicitly - the call to <literal>commit()</literal> automatically triggers ""the synchronization (depending upon the <link linkend=\"objectstate-flushing""\">FlushMode</link> for the session. A call to <literal>close()</literal> ""marks the end of a session. The main implication of <literal>close()</""literal> is that the JDBC connection will be relinquished by the session. ""This Java code is portable and runs in both non-managed and JTA environments."msgstr """Você não pode chamar <literal>flush()</literal> do <literal>Session()</""literal> explicitamente - a chamada ao <literal>commit()</literal> dispara ""automaticamente a sincronização para a sessão (dependendo do <xref linkend=""\"objectstate-flushing\"> FlushMode</xref>). Uma chamada ao <literal>close()""</literal> marca o fim de uma sessão. A principal implicação do ""<literal>close()</literal> é que a conexão JDBC será abandonada pela sessão. ""Este código Java é portável e funciona em ambientes não gerenciado e de JTA."#. Tag: para#: transactions.xml:433#, no-c-formatmsgid """A much more flexible solution is Hibernate's built-in \"current session\" ""context management, as described earlier:"msgstr """Uma solução muito mais flexível é gerência integrada de contexto da \"sessão ""atual\" do Hibernate, como descrito anteriormente:"#. Tag: programlisting#: transactions.xml:438#, no-c-formatmsgid """<![CDATA[// Non-managed environment idiom with getCurrentSession()\n""try {\n"" factory.getCurrentSession().beginTransaction();\n""\n"" // do some work\n"" ...\n""\n"" factory.getCurrentSession().getTransaction().commit();\n""}\n""catch (RuntimeException e) {\n"" factory.getCurrentSession().getTransaction().rollback();\n"" throw e; // or display error message\n""}]]>"msgstr ""#. Tag: para#: transactions.xml:440#, no-c-formatmsgid """You will very likely never see these code snippets in a regular application; ""fatal (system) exceptions should always be caught at the \"top\". In other ""words, the code that executes Hibernate calls (in the persistence layer) and ""the code that handles <literal>RuntimeException</literal> (and usually can ""only clean up and exit) are in different layers. The current context ""management by Hibernate can significantly simplify this design, as all you ""need is access to a <literal>SessionFactory</literal>. Exception handling is ""discussed later in this chapter."msgstr """Você muito provavelmente nunca verá estes fragmentos de código em uma ""aplicação regular; as exceções fatais (do sistema) devem sempre ser pegas no ""\"alto\". Ou seja, o código que executa chamadas do Hibernate (na camada de ""persistência) e o código que trata <literal>RuntimeException</literal> (e ""geralmente pode somente limpar acima e na saída) estão em camadas ""diferentes. O gerenciamento do contexto atual feito pelo Hibernate pode ""significativamente simplificar este projeto, como tudo que você necessita é ""do acesso a um <literal>SessionFactory</literal>. A manipulação de exceção é ""discutida mais tarde neste capítulo."#. Tag: para#: transactions.xml:450#, no-c-formatmsgid """Note that you should select <literal>org.hibernate.transaction.""JDBCTransactionFactory</literal> (which is the default), and for the second ""example <literal>\"thread\"</literal> as your <literal>hibernate.""current_session_context_class</literal>."msgstr """Note que você deve selecionar <literal>org.hibernate.transaction.""JDBCTransactionFactory</literal> (que é o padrão) e para o segundo exemplo ""<literal>\"thread\"</literal> como seu <literal>hibernate.""current_session_context_class</literal>."#. Tag: title#: transactions.xml:459#, no-c-formatmsgid "Using JTA"msgstr "Usando JTA"#. Tag: para#: transactions.xml:461#, no-c-formatmsgid """If your persistence layer runs in an application server (e.g. behind EJB ""session beans), every datasource connection obtained by Hibernate will ""automatically be part of the global JTA transaction. You can also install a ""standalone JTA implementation and use it without EJB. Hibernate offers two ""strategies for JTA integration."msgstr """Se sua camada de persistência funcionar em um servidor de aplicação (por ""exemplo, dentro dos EJB session beans), cada conexão do datasource obtida ""pelo Hibernate automaticamente fará parte da transação global de JTA. Você ""pode também instalar uma implementação standalone de JTA e usá-la sem EJB. O ""Hibernate oferece duas estratégias para a integração de JTA."#. Tag: para#: transactions.xml:468#, no-c-formatmsgid """If you use bean-managed transactions (BMT) Hibernate will tell the ""application server to start and end a BMT transaction if you use the ""<literal>Transaction</literal> API. So, the transaction management code is ""identical to the non-managed environment."msgstr """Se você usar bean-managed transactions (BMT - transações gerenciadas por ""bean) o Hibernate dirá ao servidor de aplicação para começar e para terminar ""uma transação de BMT se você usar a API Transaction. Assim, o código de ""gerência de transação é idêntico ao ambiente não gerenciado."#. Tag: programlisting#: transactions.xml:474#, no-c-formatmsgid """<![CDATA[// BMT idiom\n""Session sess = factory.openSession();\n""Transaction tx = null;\n""try {\n"" tx = sess.beginTransaction();\n""\n"" // do some work\n"" ...\n""\n"" tx.commit();\n""}\n""catch (RuntimeException e) {\n"" if (tx != null) tx.rollback();\n"" throw e; // or display error message\n""}\n""finally {\n"" sess.close();\n""}]]>"msgstr ""#. Tag: para#: transactions.xml:476#, no-c-formatmsgid """If you want to use a transaction-bound <literal>Session</literal>, that is, ""the <literal>getCurrentSession()</literal> functionality for easy context ""propagation, you will have to use the JTA <literal>UserTransaction</literal> ""API directly:"msgstr """Se você quiser usar um <literal>Session</literal> limitada por transação, ""isto é, a funcionalidade do <literal>getCurrentSession()</literal> para a ""propagação fácil do contexto, você terá que usar diretamente a API JTA ""<literal>UserTransaction</literal>:"#. Tag: programlisting#: transactions.xml:482#, no-c-formatmsgid """<![CDATA[// BMT idiom with getCurrentSession()\n""try {\n"" UserTransaction tx = (UserTransaction)new InitialContext()\n"" .lookup(\"java:comp/UserTransaction\");\n""\n"" tx.begin();\n""\n"" // Do some work on Session bound to transaction\n"" factory.getCurrentSession().load(...);\n"" factory.getCurrentSession().persist(...);\n""\n"" tx.commit();\n""}\n""catch (RuntimeException e) {\n"" tx.rollback();\n"" throw e; // or display error message\n""}]]>"msgstr ""#. Tag: para#: transactions.xml:484#, no-c-formatmsgid """With CMT, transaction demarcation is done in session bean deployment ""descriptors, not programatically, hence, the code is reduced to:"msgstr """Com CMT, a demarcação da transação é feita em descritores de deployment do ""session beans, não programaticamente, conseqüentemente, o código é reduzido ""a:"#. Tag: programlisting#: transactions.xml:489#, no-c-formatmsgid """<![CDATA[// CMT idiom\n"" Session sess = factory.getCurrentSession();\n""\n"" // do some work\n"" ...\n""]]>"msgstr ""#. Tag: para#: transactions.xml:491#, no-c-formatmsgid """In a CMT/EJB even rollback happens automatically, since an unhandled ""<literal>RuntimeException</literal> thrown by a session bean method tells ""the container to set the global transaction to rollback. <emphasis>This ""means you do not need to use the Hibernate <literal>Transaction</literal> ""API at all with BMT or CMT, and you get automatic propagation of the ""\"current\" Session bound to the transaction.</emphasis>"msgstr """Em um CMT/EJB mesmo um rollback acontece automaticamente, desde que uma ""exeção <literal>RuntimeException</literal> não tratável seja lançada por um ""método de um session bean que informa ao contêiner ajustar a transação ""global ao rollback. <emphasis>Isto significa que você não necessita usar a ""API <literal>Transaction</literal> do Hibernate em tudo com BMT ou CMT e ""você obtém a propagação automática do Session \"atual\" limitada à transação.""</emphasis>"#. Tag: para#: transactions.xml:499#, no-c-formatmsgid """Note that you should choose <literal>org.hibernate.transaction.""JTATransactionFactory</literal> if you use JTA directly (BMT), and ""<literal>org.hibernate.transaction.CMTTransactionFactory</literal> in a CMT ""session bean, when you configure Hibernate's transaction factory. Remember ""to also set <literal>hibernate.transaction.manager_lookup_class</literal>. ""Furthermore, make sure that your <literal>hibernate.""current_session_context_class</literal> is either unset (backwards ""compatiblity), or set to <literal>\"jta\"</literal>."msgstr """Veja que você deverá escolher <literal>org.hibernate.transaction.""JTATransactionFactory</literal> se você usar o JTA diretamente (BMT) e ""<literal>org.hibernate.transaction.CMTTransactionFactory</literal> em um CMT ""session bean, quando você configura a fábrica de transação do Hibernate. ""Lembre-se também de configurar o <literal>hibernate.transaction.""manager_lookup_class</literal>. Além disso, certifique-se que seu ""<literal>hibernate.current_session_context_class</literal> ou não é ""configurado (compatibilidade com o legado) ou é definido para <literal>\"jta""\"</literal>."#. Tag: para#: transactions.xml:508#, no-c-formatmsgid """The <literal>getCurrentSession()</literal> operation has one downside in a ""JTA environment. There is one caveat to the use of <literal>after_statement</""literal> connection release mode, which is then used by default. Due to a ""silly limitation of the JTA spec, it is not possible for Hibernate to ""automatically clean up any unclosed <literal>ScrollableResults</literal> or ""<literal>Iterator</literal> instances returned by <literal>scroll()</"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -