📄 transactions.po
字号:
#, no-c-formatmsgid "close the session"msgstr "Fermeture de la session (Close)"#. Tag: para#: transactions.xml:400#, no-c-formatmsgid "handle exceptions"msgstr "Gestion des exceptions"#. Tag: para#: transactions.xml:406#, no-c-formatmsgid """Flushing the session has been discussed earlier, we'll now have a closer ""look at transaction demarcation and exception handling in both managed- and ""non-managed environments."msgstr """La synchronisation de bdd depuis la session (flush) a déjà été expliqué, ""nous nous attarderons maintenant à la démarcation des transactions et à la ""gestion des exceptions dans les environnements légers et les environnements ""J2EE."#. Tag: title#: transactions.xml:413#, no-c-formatmsgid "Non-managed environment"msgstr "Environnement non managé"#. Tag: para#: transactions.xml:415#, no-c-formatmsgid """If a Hibernate persistence layer runs in a non-managed environment, database ""connections are usually handled by simple (i.e. non-DataSource) connection ""pools from which Hibernate obtains connections as needed. The session/""transaction handling idiom looks like this:"msgstr """Si la couche de persistance Hibernate s'exécute dans un environnement non ""managé, les connexions à la base de données seront généralement prises en ""charge par le mécanisme de pool d'Hibernate. La gestion de la session et de ""la transaction se fera donc de la manière suivante:"#. Tag: programlisting#: transactions.xml:422#, 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 """Vous n'avez pas à invoquer <literal>flush()</literal> explicitement sur la ""<literal>Session</literal> - l'appel de <literal>commit()</literal> ""déclenchera automatiquement la synchronisation (selon le <xref linkend=""\"objectstate-flushing\">FlushMode</xref> de la session. Un appel à ""<literal>close()</literal> marque la fin de la session. La conséquence ""directe est que la connexion à la base de données sera relachée par la ""session. Ce code est portable est fonctionne dans les environnements non ""managé ET les environnements 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 """Une solution plus flexible est la gestion par contexte fourni par Hibernate ""que nous avons déjà rencontré:"#. 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 """Vous ne verrez probablement jamais ces exemples de code dans les ""applications; les exceptions fatales (exceptions du système) ne devraient ""être traitées que dans la couche la plus \"haute\". En d'autres termes, le ""code qui exécute les appels à Hibernate (à la couche de persistance) et le ""code qui gère les <literal>RuntimeException</literal> (qui ne peut ""généralement effectuer qu'un nettoyage et une sortie) sont dans des couches ""différentes. La gestion du contexte courant par Hibernate peut simplifier ""notablement ce design, puisque vous devez accéder à la gestion des ""exceptions de la <literal>SessionFactory</literal>, ce qui est décrit plus ""tard dans ce chapitre."#. 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 """Notez que vous devriez sélectionner <literal>org.hibernate.transaction.""JDBCTransactionFactory</literal> (le défaut), pour le second exemple ""<literal>\"thread\"</literal> comme <literal>hibernate.""current_session_context_class</literal>."#. Tag: title#: transactions.xml:459#, no-c-formatmsgid "Using JTA"msgstr "Utilisation de 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 """Si votre couche de persistance s'exécute dans un serveur d'application (par ""exemple, derrière un EJB Session Bean), toutes les datasource utilisées par ""Hibernate feront automatiquement partie de transactions JTA globales. ""Hibernate propose deux stratégies pour réussir cette intégration."#. 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 """Si vous utilisez des transactions gérées par un EJB (bean managed ""transactions - BMT), Hibernate informera le serveur d'application du début ""et de la fin des transactions si vous utilisez l'API <literal>Transaction</""literal> . Ainsi, le code de gestion des transactions sera identique dans ""les deux types d'environnements."#. 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 "Ou encore, avec la gestion automatique de contexte:"#. 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 """Avec CMT, la démarcation des transactions est faite dans les descripteurs de ""déploiement des Beans Sessions et non de manière programmmatique, ceci ""réduit le code:"#. 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 "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -