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

📄 tutorial.po

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 PO
📖 第 1 页 / 共 5 页
字号:
"Total time: 1 second ]]>"msgstr ""#. Tag: title#: tutorial.xml:334#, no-c-formatmsgid "Startup and helpers"msgstr "スタートアップとヘルパ"#. 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 """さて <literal>Event</literal> オブジェクトをロードしたり格納したりする準備が""できました。 しかしまずはインフラストラクチャのコードを書いて、セットアップを""完了する必要があります。 まずはHibernateをスタートアップしなければなりませ""ん。 このスタートアップには、グローバルの <literal>SessionFactory</literal> ""オブジェクトを生成して、 それをアプリケーションのコードでアクセスしやすい場所""に格納することが含まれます。 <literal>SessionFactory</literal> は新しく ""<literal>Session</literal> をオープンすることができます。 <literal>Session</""literal> はシングルスレッドの作業単位(Unit of Work)を表現します。 それに対し""<literal>SessionFactory</literal> はスレッドセーフのグローバルオブジェクトで""あり、 一度だけインスタンス化されます。"#. 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 """ここでスタートアップを行い、 便利に <literal>SessionFactory</literal> へアク""セスする <literal>HibernateUtil</literal> ヘルパクラスを作成します。 実装を見""てみましょう:"#. 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 """このクラスは静的初期化ブロック(クラスがロードされるときにJVMによって一度だけ""呼ばれる) でグローバルの <literal>SessionFactory</literal> を生成するだけで""はなく、 静的シングルトンの使用を隠蔽します。 アプリケーションサーバーのJNDI""から <literal>SessionFactory</literal> を ルックアップするのと同様です。"#. 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 """設定ファイル内で <literal>SessionFactory</literal> に名前を与えると、 ""Hibernateは <literal>SessionFactory</literal> 構築後にJNDIに対しバインドを行""おうとします。 このコードを完全に排除するためには、 JMXデプロイメントを利用し""て JMXを利用できるコンテナをインスタンス化し、 <literal>HibernateService</""literal> をJNDIへバインドすることもできます。 これらの高度なオプションは、""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 """<literal>HibernateUtil.java</literal> を開発ソースディレクトリにある ""<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 """これは問題なく再コンパイルできるはずです。 最後にロギングシステムを設定する必""要があります。 Hibernateはcommons loggingを使うため、Log4jとJDK 1.4 loggingの""選択をする必要がありません。 ほとんどの開発者が好むのはLog4jです。 Hibernate""ディストリビューション(の<literal>etc/</literal> ディレクトリ)から ""<literal>log4j.properties</literal> をあなたの <literal>src</literal> ディレ""クトリ内の <literal>hibernate.cfg.xml</literal> の隣にコピーしてください。 設""定例を見て、冗長な出力がよければ設定を変更してください。 デフォルトでは""Hibernateのスタートアップメッセージだけが標準出力に表示されます。"#. 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 """チュートリアルのインフラは完全です。 Hibernateを使って実際の作業をする準備が""整いました。"#. Tag: title#: tutorial.xml:395#, no-c-formatmsgid "Loading and storing objects"msgstr "オブジェクトのロードと格納"#. 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 """ついにオブジェクトのロードと格納にHibernateを使うことができます。 ""<literal>main()</literal> メソッドを持つ <literal>EventManager</literal> クラ""スを書きます:"#. 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 """新しい <literal>Event</literal> オブジェクトを生成し、それをHibernateに渡しま""す。 今ではHibernateがSQLを処理し、データベースで <literal>INSERT</literal> ""を実行します。 実行前に <literal>Session</literal> と <literal>Transaction</""literal> を処理するコードを確認してください。"#. 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 """<literal>Session</literal> は1つの作業単位(Unit of Work)です。 当分の間、話を""簡単にするために、 <literal>Session</literal> と <literal>Transaction</""literal> の対応を一対一と仮定します。 使用しているトランザクション・システム""(このケースではJTAと共存できる単純なJDBC)からコードを保護するために、 ""Hibernate <literal>Session</literal> 上で利用可能な <literal>Transaction</""literal> APIを使用します。"#. 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 """<literal>sessionFactory.getCurrentSession()</literal> はなにをするのでしょう""か? まず、いったん <literal>SessionFactory</literal> を取得し保持すれば ""( <literal>HibernateUtil</literal> のおかげで簡単です)、このメソッドを何度""でも、 どこからでも呼び出すことが出来ます。 <literal>getCurrentSession()</""literal> メソッドは常に「現在の」作業単位(Unit of Work)を返します。 ""<literal>hibernate.cfg.xml</literal> のこの機能の設定で、\"thread\"を指定した""ことを思い出してください。 このため現在の作業単位のスコープは、このアプリケー""ションを実行する現在のJavaスレッドです。 しかしこれで全てではありません。"#. Tag: para#: tutorial.xml:430#, no-c-formatmsgid """A <literal>Session</literal> begins when it is first needed, when the first "

⌨️ 快捷键说明

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