~raginggoblin/infolog/infolog

« back to all changes in this revision

Viewing changes to InfologServer/lib/hibernate-distribution-3.3.2.GA/documentation/manual/ja-JP/html/session-configuration.html

  • Committer: Raging Goblin
  • Date: 2013-11-16 16:51:32 UTC
  • Revision ID: raging_goblin-20131116165132-weujnptzc88uy4ah
Mavenized the project, now using shared project InfologSync

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
 
<!DOCTYPE html
3
 
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
 
<html xmlns="http://www.w3.org/1999/xhtml"><head><title xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory">第3章 設定</title><link rel="stylesheet" href="css/hibernate.css" type="text/css"/><meta xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" name="generator" content="DocBook XSL Stylesheets V1.72.0"/><link rel="start" href="index.html" title="HIBERNATE - Relational Persistence for Idiomatic Java"/><link rel="up" href="index.html" title="HIBERNATE - Relational Persistence for Idiomatic Java"/><link rel="prev" href="architecture.html" title="第2章 アーキテクチャ"/><link rel="next" href="persistent-classes.html" title="第4章 永続クラス"/><link rel="copyright" href="ln-Legal_Notice.html" title="Legal Notice"/></head><body><p id="title"><a href="http://www.hibernate.org" class="site_href"><strong>Hibernate.org</strong></a><a href="http://hibernate.org/Documentation/DocumentationOverview" class="doc_href"><strong>Community Documentation</strong></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="architecture.html"><strong>前のページ</strong></a></li><li class="next"><a accesskey="n" href="persistent-classes.html"><strong>次のページ</strong></a></li></ul><div class="chapter" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="session-configuration"/>第3章 設定</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="session-configuration.html#configuration-programmatic">3.1. プログラム上の設定</a></span></dt><dt><span class="sect1"><a href="session-configuration.html#configuration-sessionfactory">3.2. SessionFactoryを取得する</a></span></dt><dt><span class="sect1"><a href="session-configuration.html#configuration-hibernatejdbc">3.3. JDBCコネクション</a></span></dt><dt><span class="sect1"><a href="session-configuration.html#configuration-optional">3.4. オプション設定プロパティ</a></span></dt><dd><dl><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-dialects">3.4.1. SQL 方言(Dialect)</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-outerjoin">3.4.2. 外部結合フェッチ</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-binarystreams">3.4.3. バイナリストリーム</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-cacheprovider">3.4.4. 2次キャッシュとクエリーキャッシュ</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-querysubstitution">3.4.5. クエリー言語の置き換え</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-statistics">3.4.6. Hibernate 統計</a></span></dt></dl></dd><dt><span class="sect1"><a href="session-configuration.html#configuration-logging">3.5. ロギング</a></span></dt><dt><span class="sect1"><a href="session-configuration.html#configuration-namingstrategy">3.6. <code class="literal">NamingStrategy</code> の実装</a></span></dt><dt><span class="sect1"><a href="session-configuration.html#configuration-xmlconfig">3.7. XML設定ファイル</a></span></dt><dt><span class="sect1"><a href="session-configuration.html#configuration-j2ee">3.8. J2EEアプリケーションサーバとの統合</a></span></dt><dd><dl><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-transactionstrategy">3.8.1. トランザクション戦略設定</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-jndi">3.8.2. <code class="literal">SessionFactory</code> のJNDIへの登録</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-j2ee-currentsession">3.8.3. JTAによる現在のセッションコンテキストマネージメント</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-j2ee-jmx">3.8.4. JMXデプロイメント</a></span></dt></dl></dd></dl></div><p>Hibernate is designed to operate in many different environments and, as such, there is a broad range of configuration parameters. Fortunately, most have sensible default values and Hibernate is distributed with an example <code class="literal">hibernate.properties</code> file in <code class="literal">etc/</code> that displays the various options. Simply put the example file in your classpath and customize it to suit your needs. </p><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-programmatic"/>3.1. プログラム上の設定</h2></div></div></div><p>An instance of <code class="classname">org.hibernate.cfg.Configuration</code> represents an entire set of mappings of an application's Java types to an SQL database. The <code class="classname">org.hibernate.cfg.Configuration</code> is used to build an immutable <code class="interfacename">org.hibernate.SessionFactory</code>. The mappings are compiled from various XML mapping files. </p><p>You can obtain a <code class="classname">org.hibernate.cfg.Configuration</code> instance by instantiating it directly and specifying XML mapping documents. If the mapping files are in the classpath, use <code class="literal">addResource()</code>. For example: </p><pre class="programlisting">Configuration cfg = new Configuration()
5
 
    .addResource("Item.hbm.xml")
6
 
    .addResource("Bid.hbm.xml");</pre><p>An alternative way is to specify the mapped class and allow Hibernate to find the mapping document for you: </p><pre class="programlisting">Configuration cfg = new Configuration()
7
 
    .addClass(org.hibernate.auction.Item.class)
8
 
    .addClass(org.hibernate.auction.Bid.class);</pre><p>Hibernate will then search for mapping files named <code class="filename">/org/hibernate/auction/Item.hbm.xml</code> and <code class="filename">/org/hibernate/auction/Bid.hbm.xml</code> in the classpath. This approach eliminates any hardcoded filenames. </p><p>A <code class="classname">org.hibernate.cfg.Configuration</code> also allows you to specify configuration properties. For example: </p><pre class="programlisting">Configuration cfg = new Configuration()
9
 
    .addClass(org.hibernate.auction.Item.class)
10
 
    .addClass(org.hibernate.auction.Bid.class)
11
 
    .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
12
 
    .setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test")
13
 
    .setProperty("hibernate.order_updates", "true");</pre><p>This is not the only way to pass configuration properties to Hibernate. Some alternative options include: </p><div xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="orderedlist"><ol><li><p>Pass an instance of <code class="classname">java.util.Properties</code> to <code class="literal">Configuration.setProperties()</code>. </p></li><li><p>Place a file named <code class="filename">hibernate.properties</code> in a root directory of the classpath. </p></li><li><p><code class="literal">System</code> プロパティが <code class="literal">java -Dproperty=value</code> を使うように設定します。 </p></li><li><p>Include <code class="literal">&lt;property&gt;</code> elements in <code class="literal">hibernate.cfg.xml</code> (this is discussed later). </p></li></ol></div><p>If you want to get started quickly<code class="filename">hibernate.properties</code> is the easiest approach. </p><p>The <code class="classname">org.hibernate.cfg.Configuration</code> is intended as a startup-time object that will be discarded once a <code class="literal">SessionFactory</code> is created. </p></div><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-sessionfactory"/>3.2. SessionFactoryを取得する</h2></div></div></div><p>When all mappings have been parsed by the <code class="classname">org.hibernate.cfg.Configuration</code>, the application must obtain a factory for <code class="interfacename">org.hibernate.Session</code> instances. This factory is intended to be shared by all application threads: </p><pre class="programlisting">SessionFactory sessions = cfg.buildSessionFactory();</pre><p>Hibernate does allow your application to instantiate more than one <code class="interfacename">org.hibernate.SessionFactory</code>. This is useful if you are using more than one database. </p></div><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-hibernatejdbc"/>3.3. JDBCコネクション</h2></div></div></div><p>It is advisable to have the <code class="interfacename">org.hibernate.SessionFactory</code> create and pool JDBC connections for you. If you take this approach, opening a <code class="interfacename">org.hibernate.Session</code> is as simple as: </p><pre class="programlisting">Session session = sessions.openSession(); // open a new Session</pre><p>Once you start a task that requires access to the database, a JDBC connection will be obtained from the pool. </p><p>Before you can do this, you first need to pass some JDBC connection properties to Hibernate. All Hibernate property names and semantics are defined on the class <code class="classname">org.hibernate.cfg.Environment</code>. The most important settings for JDBC connection configuration are outlined below. </p><p>Hibernate will obtain and pool connections using <code class="classname">java.sql.DriverManager</code> if you set the following properties: </p><div class="table"><a id="d0e1745"/><p class="title"><b>表 3.1. Hibernate JDBCプロパティ</b></p><div class="table-contents"><table summary="Hibernate JDBCプロパティ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>プロパティ名</th><th>意味</th></tr></thead><tbody><tr><td>
14
 
                    <span class="property">hibernate.connection.driver_class</span>
15
 
                </td><td>
16
 
                    <span class="emphasis"><em>JDBCドライバクラス</em></span>
17
 
                </td></tr><tr><td>
18
 
                    <span class="property">hibernate.connection.url</span>
19
 
                </td><td>
20
 
                    <span class="emphasis"><em>jdbc URL</em></span>
21
 
                </td></tr><tr><td>
22
 
                    <span class="property">hibernate.connection.username</span>
23
 
                </td><td>
24
 
                    <span class="emphasis"><em>database user</em></span>
25
 
                </td></tr><tr><td>
26
 
                    <span class="property">hibernate.connection.password</span>
27
 
                </td><td>
28
 
                    <span class="emphasis"><em>database user password</em></span>
29
 
                </td></tr><tr><td>
30
 
                    <span class="property">hibernate.connection.pool_size</span>
31
 
                </td><td>
32
 
                    <span class="emphasis"><em>プールするコネクションの最大数</em></span>
33
 
                </td></tr></tbody></table></div></div><br class="table-break"/><p>Hibernate's own connection pooling algorithm is, however, quite rudimentary. It is intended to help you get started and is <span class="emphasis"><em>not intended for use in a production system</em></span>, or even for performance testing. You should use a third party pool for best performance and stability. Just replace the <span class="property">hibernate.connection.pool_size</span> property with connection pool specific settings. This will turn off Hibernate's internal pool. For example, you might like to use c3p0. </p><p>C3P0 is an open source JDBC connection pool distributed along with Hibernate in the <code class="filename">lib</code> directory. Hibernate will use its <code class="classname">org.hibernate.connection.C3P0ConnectionProvider</code> for connection pooling if you set <span class="property">hibernate.c3p0.*</span> properties. If you would like to use Proxool, refer to the packaged <code class="filename">hibernate.properties</code> and the Hibernate web site for more information. </p><p>The following is an example <code class="filename">hibernate.properties</code> file for c3p0: </p><a id="c3p0-configuration"/><pre class="programlisting">hibernate.connection.driver_class = org.postgresql.Driver
34
 
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
35
 
hibernate.connection.username = myuser
36
 
hibernate.connection.password = secret
37
 
hibernate.c3p0.min_size=5
38
 
hibernate.c3p0.max_size=20
39
 
hibernate.c3p0.timeout=1800
40
 
hibernate.c3p0.max_statements=50
41
 
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect</pre><p>For use inside an application server, you should almost always configure Hibernate to obtain connections from an application server <code class="interfacename">javax.sql.Datasource</code> registered in JNDI. You will need to set at least one of the following properties: </p><div class="table"><a id="d0e1847"/><p class="title"><b>表 3.2. Hibernate データソースプロパティ</b></p><div class="table-contents"><table summary="Hibernate データソースプロパティ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>プロパティ名</th><th>意味</th></tr></thead><tbody><tr><td>
42
 
                    <span class="property">hibernate.connection.datasource</span>
43
 
                </td><td>
44
 
                    <span class="emphasis"><em>データソースのJNDI名</em></span>
45
 
                </td></tr><tr><td>
46
 
                    <span class="property">hibernate.jndi.url</span>
47
 
                </td><td><span class="emphasis"><em>URL of the JNDI provider</em></span> (optional) </td></tr><tr><td>
48
 
                    <span class="property">hibernate.jndi.class</span>
49
 
                </td><td><span class="emphasis"><em>class of the JNDI <code class="literal">InitialContextFactory</code></em></span> (optional) </td></tr><tr><td>
50
 
                    <span class="property">hibernate.connection.username</span>
51
 
                </td><td><span class="emphasis"><em>database user</em></span> (optional) </td></tr><tr><td>
52
 
                    <span class="property">hibernate.connection.password</span>
53
 
                </td><td><span class="emphasis"><em>database user password</em></span> (optional) </td></tr></tbody></table></div></div><br class="table-break"/><p>Here is an example <code class="filename">hibernate.properties</code> file for an application server provided JNDI datasource: </p><pre class="programlisting">hibernate.connection.datasource = java:/comp/env/jdbc/test
54
 
hibernate.transaction.factory_class = \
55
 
    org.hibernate.transaction.JTATransactionFactory
56
 
hibernate.transaction.manager_lookup_class = \
57
 
    org.hibernate.transaction.JBossTransactionManagerLookup
58
 
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect</pre><p>JNDIデータソースから取得したJDBCコネクションは、アプリケーションサーバの コンテナ管理トランザクションに自動的に参加します。 </p><p>Arbitrary connection properties can be given by prepending "<code class="literal">hibernate.connection</code>" to the connection property name. For example, you can specify a <span class="property">charSet</span> connection property using <span class="property">hibernate.connection.charSet</span>. </p><p>You can define your own plugin strategy for obtaining JDBC connections by implementing the interface <code class="interfacename">org.hibernate.connection.ConnectionProvider</code>, and specifying your custom implementation via the <span class="property">hibernate.connection.provider_class</span> property. </p></div><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-optional"/>3.4. オプション設定プロパティ</h2></div></div></div><p>There are a number of other properties that control the behavior of Hibernate at runtime. All are optional and have reasonable default values. </p><p>
59
 
                </p><div xmlns:rf="java:org.jboss.highlight.XhtmlRendererFactory" class="warning"><h2>警告</h2><span class="emphasis"><em>Some of these properties are "system-level" only.</em></span> System-level properties can be set only via <code class="literal">java -Dproperty=value</code> or <code class="filename">hibernate.properties</code>. They <span class="emphasis"><em>cannot</em></span> be set by the other techniques described above.</div><p>
60
 
        </p><div class="table"><a id="configuration-optional-properties"/><p class="title"><b>表 3.3. Hibernate設定プロパティ</b></p><div class="table-contents"><table summary="Hibernate設定プロパティ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>プロパティ名</th><th>意味</th></tr></thead><tbody><tr><td>
61
 
                            <span class="property">hibernate.dialect</span>
62
 
                        </td><td>The classname of a Hibernate <code class="classname">org.hibernate.dialect.Dialect</code> which allows Hibernate to generate SQL optimized for a particular relational database. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">full.classname.of.Dialect</code> </p>
63
 
                            <p>In most cases Hibernate will actually be able to choose the correct <code class="classname">org.hibernate.dialect.Dialect</code> implementation based on the <code class="literal">JDBC metadata</code> returned by the JDBC driver. </p>
64
 
                        </td></tr><tr><td>
65
 
                            <span class="property">hibernate.show_sql</span>
66
 
                        </td><td>Write all SQL statements to console. This is an alternative to setting the log category <code class="literal">org.hibernate.SQL</code> to <code class="literal">debug</code>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
67
 
                        </td></tr><tr><td>
68
 
                            <span class="property">hibernate.format_sql</span>
69
 
                        </td><td>Pretty print the SQL in the log and console. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
70
 
                        </td></tr><tr><td>
71
 
                            <span class="property">hibernate.default_schema</span>
72
 
                        </td><td>Qualify unqualified table names with the given schema/tablespace in generated SQL. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">SCHEMA_NAME</code> </p>
73
 
                        </td></tr><tr><td>
74
 
                            <span class="property">hibernate.default_catalog</span>
75
 
                        </td><td>Qualifies unqualified table names with the given catalog in generated SQL. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">CATALOG_NAME</code> </p>
76
 
                        </td></tr><tr><td>
77
 
                            <span class="property">hibernate.session_factory_name</span>
78
 
                        </td><td>The <code class="interfacename">org.hibernate.SessionFactory</code> will be automatically bound to this name in JNDI after it has been created. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">jndi/composite/name</code> </p>
79
 
                        </td></tr><tr><td>
80
 
                            <span class="property">hibernate.max_fetch_depth</span>
81
 
                        </td><td>Sets a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one). A <code class="literal">0</code> disables default outer join fetching. <p><span class="strong"><strong>e.g.</strong></span> recommended values between <code class="literal">0</code> and <code class="literal">3</code> </p>
82
 
                        </td></tr><tr><td>
83
 
                            <span class="property">hibernate.default_batch_fetch_size</span>
84
 
                        </td><td>Sets a default size for Hibernate batch fetching of associations. <p><span class="strong"><strong>e.g.</strong></span> recommended values <code class="literal">4</code>, <code class="literal">8</code>, <code class="literal">16</code> </p>
85
 
                        </td></tr><tr><td>
86
 
                            <span class="property">hibernate.default_entity_mode</span>
87
 
                        </td><td>Sets a default mode for entity representation for all sessions opened from this <code class="literal">SessionFactory</code> <p><code class="literal">dynamic-map</code>, <code class="literal">dom4j</code>, <code class="literal">pojo</code> </p>
88
 
                        </td></tr><tr><td>
89
 
                            <span class="property">hibernate.order_updates</span>
90
 
                        </td><td>Forces Hibernate to order SQL updates by the primary key value of the items being updated. This will result in fewer transaction deadlocks in highly concurrent systems. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
91
 
                        </td></tr><tr><td>
92
 
                            <span class="property">hibernate.generate_statistics</span>
93
 
                        </td><td>If enabled, Hibernate will collect statistics useful for performance tuning. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
94
 
                        </td></tr><tr><td>
95
 
                            <span class="property">hibernate.use_identifer_rollback</span>
96
 
                        </td><td>If enabled, generated identifier properties will be reset to default values when objects are deleted. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
97
 
                        </td></tr><tr><td>
98
 
                            <span class="property">hibernate.use_sql_comments</span>
99
 
                        </td><td>If turned on, Hibernate will generate comments inside the SQL, for easier debugging, defaults to <code class="literal">false</code>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
100
 
                        </td></tr></tbody></table></div></div><br class="table-break"/><div class="table"><a id="configuration-jdbc-properties"/><p class="title"><b>表 3.4. Hibernate JDBC とコネクションプロパティ</b></p><div class="table-contents"><table summary="Hibernate JDBC とコネクションプロパティ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>プロパティ名</th><th>意味</th></tr></thead><tbody><tr><td>
101
 
                            <span class="property">hibernate.jdbc.fetch_size</span>
102
 
                        </td><td>A non-zero value determines the JDBC fetch size (calls <code class="literal">Statement.setFetchSize()</code>). </td></tr><tr><td>
103
 
                            <span class="property">hibernate.jdbc.batch_size</span>
104
 
                        </td><td>A non-zero value enables use of JDBC2 batch updates by Hibernate. <p><span class="strong"><strong>e.g.</strong></span> recommended values between <code class="literal">5</code> and <code class="literal">30</code> </p>
105
 
                        </td></tr><tr><td>
106
 
                            <span class="property">hibernate.jdbc.batch_versioned_data</span>
107
 
                        </td><td>Set this property to <code class="literal">true</code> if your JDBC driver returns correct row counts from <code class="literal">executeBatch()</code>. Iit is usually safe to turn this option on. Hibernate will then use batched DML for automatically versioned data. Defaults to <code class="literal">false</code>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
108
 
                        </td></tr><tr><td>
109
 
                            <span class="property">hibernate.jdbc.factory_class</span>
110
 
                        </td><td>Select a custom <code class="interfacename">org.hibernate.jdbc.Batcher</code>. Most applications will not need this configuration property. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">classname.of.BatcherFactory</code> </p>
111
 
                        </td></tr><tr><td>
112
 
                            <span class="property">hibernate.jdbc.use_scrollable_resultset</span>
113
 
                        </td><td>Enables use of JDBC2 scrollable resultsets by Hibernate. This property is only necessary when using user-supplied JDBC connections. Hibernate uses connection metadata otherwise. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
114
 
                        </td></tr><tr><td>
115
 
                            <span class="property">hibernate.jdbc.use_streams_for_binary</span>
116
 
                        </td><td>Use streams when writing/reading <code class="literal">binary</code> or <code class="literal">serializable</code> types to/from JDBC. <span class="emphasis"><em>*system-level property*</em></span> <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
117
 
                        </td></tr><tr><td>
118
 
                            <span class="property">hibernate.jdbc.use_get_generated_keys</span>
119
 
                        </td><td>Enables use of JDBC3 <code class="literal">PreparedStatement.getGeneratedKeys()</code> to retrieve natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+, set to false if your driver has problems with the Hibernate identifier generators. By default, it tries to determine the driver capabilities using connection metadata. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true|false</code> </p>
120
 
                        </td></tr><tr><td>
121
 
                            <span class="property">hibernate.connection.provider_class</span>
122
 
                        </td><td>The classname of a custom <code class="interfacename">org.hibernate.connection.ConnectionProvider</code> which provides JDBC connections to Hibernate. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">classname.of.ConnectionProvider</code> </p>
123
 
                        </td></tr><tr><td>
124
 
                            <span class="property">hibernate.connection.isolation</span>
125
 
                        </td><td>Sets the JDBC transaction isolation level. Check <code class="interfacename">java.sql.Connection</code> for meaningful values, but note that most databases do not support all isolation levels and some define additional, non-standard isolations. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">1, 2, 4, 8</code> </p>
126
 
                        </td></tr><tr><td>
127
 
                            <span class="property">hibernate.connection.autocommit</span>
128
 
                        </td><td>Enables autocommit for JDBC pooled connections (it is not recommended). <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
129
 
                        </td></tr><tr><td>
130
 
                            <span class="property">hibernate.connection.release_mode</span>
131
 
                        </td><td>Specifies when Hibernate should release JDBC connections. By default, a JDBC connection is held until the session is explicitly closed or disconnected. For an application server JTA datasource, use <code class="literal">after_statement</code> to aggressively release connections after every JDBC call. For a non-JTA connection, it often makes sense to release the connection at the end of each transaction, by using <code class="literal">after_transaction</code>. <code class="literal">auto</code> will choose <code class="literal">after_statement</code> for the JTA and CMT transaction strategies and <code class="literal">after_transaction</code> for the JDBC transaction strategy. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">auto</code> (default) | <code class="literal">on_close</code> | <code class="literal">after_transaction</code> | <code class="literal">after_statement</code> </p>
132
 
                            <p>This setting only affects <code class="literal">Session</code>s returned from <code class="literal">SessionFactory.openSession</code>. For <code class="literal">Session</code>s obtained through <code class="literal">SessionFactory.getCurrentSession</code>, the <code class="literal">CurrentSessionContext</code> implementation configured for use controls the connection release mode for those <code class="literal">Session</code>s. See <a href="architecture.html#architecture-current-session" title="2.5. Contextual sessions">項2.5. 「Contextual sessions」</a> </p>
133
 
                        </td></tr><tr><td><span class="property">hibernate.connection.</span><span class="emphasis"><em>&lt;propertyName&gt;</em></span> </td><td>Pass the JDBC property <span class="emphasis"><em>&lt;propertyName&gt;</em></span> to <code class="literal">DriverManager.getConnection()</code>. </td></tr><tr><td><span class="property">hibernate.jndi.</span><span class="emphasis"><em>&lt;propertyName&gt;</em></span> </td><td>Pass the property <span class="emphasis"><em>&lt;propertyName&gt;</em></span> to the JNDI <code class="literal">InitialContextFactory</code>. </td></tr></tbody></table></div></div><br class="table-break"/><div class="table"><a id="configuration-cache-properties"/><p class="title"><b>表 3.5. Hibernate キャッシュプロパティ</b></p><div class="table-contents"><table summary="Hibernate キャッシュプロパティ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>プロパティ名</th><th>意味</th></tr></thead><tbody><tr><td>
134
 
                            <code class="literal">hibernate.cache.provider_class</code>
135
 
                        </td><td>The classname of a custom <code class="literal">CacheProvider</code>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">classname.of.CacheProvider</code> </p>
136
 
                        </td></tr><tr><td>
137
 
                            <code class="literal">hibernate.cache.use_minimal_puts</code>
138
 
                        </td><td>Optimizes second-level cache operation to minimize writes, at the cost of more frequent reads. This setting is most useful for clustered caches and, in Hibernate3, is enabled by default for clustered cache implementations. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true|false</code> </p>
139
 
                        </td></tr><tr><td>
140
 
                            <code class="literal">hibernate.cache.use_query_cache</code>
141
 
                        </td><td>Enables the query cache. Individual queries still have to be set cachable. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true|false</code> </p>
142
 
                        </td></tr><tr><td>
143
 
                            <code class="literal">hibernate.cache.use_second_level_cache</code>
144
 
                        </td><td>Can be used to completely disable the second level cache, which is enabled by default for classes which specify a <code class="literal">&lt;cache&gt;</code> mapping. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true|false</code> </p>
145
 
                        </td></tr><tr><td>
146
 
                            <code class="literal">hibernate.cache.query_cache_factory</code>
147
 
                        </td><td>The classname of a custom <code class="literal">QueryCache</code> interface, defaults to the built-in <code class="literal">StandardQueryCache</code>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">classname.of.QueryCache</code> </p>
148
 
                        </td></tr><tr><td>
149
 
                            <code class="literal">hibernate.cache.region_prefix</code>
150
 
                        </td><td>A prefix to use for second-level cache region names. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">prefix</code> </p>
151
 
                        </td></tr><tr><td>
152
 
                            <code class="literal">hibernate.cache.use_structured_entries</code>
153
 
                        </td><td>Forces Hibernate to store data in the second-level cache in a more human-friendly format. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true|false</code> </p>
154
 
                        </td></tr></tbody></table></div></div><br class="table-break"/><div class="table"><a id="configuration-transaction-properties"/><p class="title"><b>表 3.6. Hibernate トランザクションプロパティ</b></p><div class="table-contents"><table summary="Hibernate トランザクションプロパティ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>プロパティ名</th><th>意味</th></tr></thead><tbody><tr><td>
155
 
                            <code class="literal">hibernate.transaction.factory_class</code>
156
 
                        </td><td>The classname of a <code class="literal">TransactionFactory</code> to use with Hibernate <code class="literal">Transaction</code> API (defaults to <code class="literal">JDBCTransactionFactory</code>). <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">classname.of.TransactionFactory</code> </p>
157
 
                        </td></tr><tr><td>
158
 
                            <code class="literal">jta.UserTransaction</code>
159
 
                        </td><td>A JNDI name used by <code class="literal">JTATransactionFactory</code> to obtain the JTA <code class="literal">UserTransaction</code> from the application server. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">jndi/composite/name</code> </p>
160
 
                        </td></tr><tr><td>
161
 
                            <code class="literal">hibernate.transaction.manager_lookup_class</code>
162
 
                        </td><td>The classname of a <code class="literal">TransactionManagerLookup</code>. It is required when JVM-level caching is enabled or when using hilo generator in a JTA environment. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">classname.of.TransactionManagerLookup</code> </p>
163
 
                        </td></tr><tr><td>
164
 
                            <code class="literal">hibernate.transaction.flush_before_completion</code>
165
 
                        </td><td>If enabled, the session will be automatically flushed during the before completion phase of the transaction. Built-in and automatic session context management is preferred, see <a href="architecture.html#architecture-current-session" title="2.5. Contextual sessions">項2.5. 「Contextual sessions」</a>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
166
 
                        </td></tr><tr><td>
167
 
                            <code class="literal">hibernate.transaction.auto_close_session</code>
168
 
                        </td><td>If enabled, the session will be automatically closed during the after completion phase of the transaction. Built-in and automatic session context management is preferred, see <a href="architecture.html#architecture-current-session" title="2.5. Contextual sessions">項2.5. 「Contextual sessions」</a>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
169
 
                        </td></tr></tbody></table></div></div><br class="table-break"/><div class="table"><a id="configuration-misc-properties"/><p class="title"><b>表 3.7. その他のプロパティ</b></p><div class="table-contents"><table summary="その他のプロパティ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>プロパティ名</th><th>意味</th></tr></thead><tbody><tr><td>
170
 
                            <code class="literal">hibernate.current_session_context_class</code>
171
 
                        </td><td>Supply a custom strategy for the scoping of the "current" <code class="literal">Session</code>. See <a href="architecture.html#architecture-current-session" title="2.5. Contextual sessions">項2.5. 「Contextual sessions」</a> for more information about the built-in strategies. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">jta</code> | <code class="literal">thread</code> | <code class="literal">managed</code> | <code class="literal">custom.Class</code> </p>
172
 
                        </td></tr><tr><td>
173
 
                            <code class="literal">hibernate.query.factory_class</code>
174
 
                        </td><td>Chooses the HQL parser implementation. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">org.hibernate.hql.ast.ASTQueryTranslatorFactory</code> or <code class="literal">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</code> </p>
175
 
                        </td></tr><tr><td>
176
 
                            <code class="literal">hibernate.query.substitutions</code>
177
 
                        </td><td>Is used to map from tokens in Hibernate queries to SQL tokens (tokens might be function or literal names, for example). <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">hqlLiteral=SQL_LITERAL, hqlFunction=SQLFUNC</code> </p>
178
 
                        </td></tr><tr><td>
179
 
                            <code class="literal">hibernate.hbm2ddl.auto</code>
180
 
                        </td><td>Automatically validates or exports schema DDL to the database when the <code class="literal">SessionFactory</code> is created. With <code class="literal">create-drop</code>, the database schema will be dropped when the <code class="literal">SessionFactory</code> is closed explicitly. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">validate</code> | <code class="literal">update</code> | <code class="literal">create</code> | <code class="literal">create-drop</code> </p>
181
 
                        </td></tr><tr><td>
182
 
                            <code class="literal">hibernate.cglib.use_reflection_optimizer</code>
183
 
                        </td><td>Enables the use of CGLIB instead of runtime reflection (System-level property). Reflection can sometimes be useful when troubleshooting. Hibernate always requires CGLIB even if you turn off the optimizer. You cannot set this property in <code class="literal">hibernate.cfg.xml</code>. <p><span class="strong"><strong>e.g.</strong></span> <code class="literal">true</code> | <code class="literal">false</code> </p>
184
 
                        </td></tr></tbody></table></div></div><br class="table-break"/><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-dialects"/>3.4.1. SQL 方言(Dialect)</h3></div></div></div><p>Always set the <code class="literal">hibernate.dialect</code> property to the correct <code class="literal">org.hibernate.dialect.Dialect</code> subclass for your database. If you specify a dialect, Hibernate will use sensible defaults for some of the other properties listed above. This means that you will not have to specify them manually. </p><div class="table"><a id="sql-dialects"/><p class="title"><b>表 3.8. Hibernate SQL Dialects (<code class="literal">hibernate.dialect</code>)</b></p><div class="table-contents"><table summary="Hibernate SQL Dialects (hibernate.dialect)" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>RDBMS</th><th>Dialect</th></tr></thead><tbody><tr><td>DB2</td><td><code class="literal">org.hibernate.dialect.DB2Dialect</code></td></tr><tr><td>DB2 AS/400</td><td><code class="literal">org.hibernate.dialect.DB2400Dialect</code></td></tr><tr><td>DB2 OS390</td><td><code class="literal">org.hibernate.dialect.DB2390Dialect</code></td></tr><tr><td>PostgreSQL</td><td><code class="literal">org.hibernate.dialect.PostgreSQLDialect</code></td></tr><tr><td>MySQL</td><td><code class="literal">org.hibernate.dialect.MySQLDialect</code></td></tr><tr><td>MySQL with InnoDB</td><td><code class="literal">org.hibernate.dialect.MySQLInnoDBDialect</code></td></tr><tr><td>MySQL with MyISAM</td><td><code class="literal">org.hibernate.dialect.MySQLMyISAMDialect</code></td></tr><tr><td>Oracle (any version)</td><td><code class="literal">org.hibernate.dialect.OracleDialect</code></td></tr><tr><td>Oracle 9i</td><td><code class="literal">org.hibernate.dialect.Oracle9iDialect</code></td></tr><tr><td>Oracle 10g</td><td><code class="literal">org.hibernate.dialect.Oracle10gDialect</code></td></tr><tr><td>Sybase</td><td><code class="literal">org.hibernate.dialect.SybaseDialect</code></td></tr><tr><td>Sybase Anywhere</td><td><code class="literal">org.hibernate.dialect.SybaseAnywhereDialect</code></td></tr><tr><td>Microsoft SQL Server</td><td><code class="literal">org.hibernate.dialect.SQLServerDialect</code></td></tr><tr><td>SAP DB</td><td><code class="literal">org.hibernate.dialect.SAPDBDialect</code></td></tr><tr><td>Informix</td><td><code class="literal">org.hibernate.dialect.InformixDialect</code></td></tr><tr><td>HypersonicSQL</td><td><code class="literal">org.hibernate.dialect.HSQLDialect</code></td></tr><tr><td>Ingres</td><td><code class="literal">org.hibernate.dialect.IngresDialect</code></td></tr><tr><td>Progress</td><td><code class="literal">org.hibernate.dialect.ProgressDialect</code></td></tr><tr><td>Mckoi SQL</td><td><code class="literal">org.hibernate.dialect.MckoiDialect</code></td></tr><tr><td>Interbase</td><td><code class="literal">org.hibernate.dialect.InterbaseDialect</code></td></tr><tr><td>Pointbase</td><td><code class="literal">org.hibernate.dialect.PointbaseDialect</code></td></tr><tr><td>FrontBase</td><td><code class="literal">org.hibernate.dialect.FrontbaseDialect</code></td></tr><tr><td>Firebird</td><td><code class="literal">org.hibernate.dialect.FirebirdDialect</code></td></tr></tbody></table></div></div><br class="table-break"/></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-outerjoin"/>3.4.2. 外部結合フェッチ</h3></div></div></div><p>If your database supports ANSI, Oracle or Sybase style outer joins, <span class="emphasis"><em>outer join fetching</em></span> will often increase performance by limiting the number of round trips to and from the database. This is, however, at the cost of possibly more work performed by the database itself. Outer join fetching allows a whole graph of objects connected by many-to-one, one-to-many, many-to-many and one-to-one associations to be retrieved in a single SQL <code class="literal">SELECT</code>. </p><p>Outer join fetching can be disabled <span class="emphasis"><em>globally</em></span> by setting the property <code class="literal">hibernate.max_fetch_depth</code> to <code class="literal">0</code>. A setting of <code class="literal">1</code> or higher enables outer join fetching for one-to-one and many-to-one associations that have been mapped with <code class="literal">fetch="join"</code>. </p><p>See <a href="performance.html#performance-fetching" title="19.1. フェッチ戦略">項19.1. 「フェッチ戦略」</a> for more information. </p></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-binarystreams"/>3.4.3. バイナリストリーム</h3></div></div></div><p>Oracle limits the size of <code class="literal">byte</code> arrays that can be passed to and/or from its JDBC driver. If you wish to use large instances of <code class="literal">binary</code> or <code class="literal">serializable</code> type, you should enable <code class="literal">hibernate.jdbc.use_streams_for_binary</code>. <span class="emphasis"><em>This is a system-level setting only.</em></span> </p></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-cacheprovider"/>3.4.4. 2次キャッシュとクエリーキャッシュ</h3></div></div></div><p>The properties prefixed by <code class="literal">hibernate.cache</code> allow you to use a process or cluster scoped second-level cache system with Hibernate. See the <a href="performance.html#performance-cache" title="19.2. 第2レベルキャッシュ">項19.2. 「第2レベルキャッシュ」</a> for more information. </p></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-querysubstitution"/>3.4.5. クエリー言語の置き換え</h3></div></div></div><p>You can define new Hibernate query tokens using <code class="literal">hibernate.query.substitutions</code>. For example: </p><pre class="programlisting">hibernate.query.substitutions true=1, false=0</pre><p>This would cause the tokens <code class="literal">true</code> and <code class="literal">false</code> to be translated to integer literals in the generated SQL. </p><pre class="programlisting">hibernate.query.substitutions toLowercase=LOWER</pre><p>This would allow you to rename the SQL <code class="literal">LOWER</code> function. </p></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-statistics"/>3.4.6. Hibernate 統計</h3></div></div></div><p>If you enable <code class="literal">hibernate.generate_statistics</code>, Hibernate exposes a number of metrics that are useful when tuning a running system via <code class="literal">SessionFactory.getStatistics()</code>. Hibernate can even be configured to expose these statistics via JMX. Read the Javadoc of the interfaces in <code class="literal">org.hibernate.stats</code> for more information. </p></div></div><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-logging"/>3.5. ロギング</h2></div></div></div><p>Hibernate utilizes <a xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.slf4j.org/">Simple Logging Facade for Java</a> (SLF4J) in order to log various system events. SLF4J can direct your logging output to several logging frameworks (NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL or logback) depending on your chosen binding. In order to setup logging you will need <code class="filename">slf4j-api.jar</code> in your classpath together with the jar file for your preferred binding - <code class="filename">slf4j-log4j12.jar</code> in the case of Log4J. See the SLF4J <a xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.slf4j.org/manual.html">documentation</a> for more detail. To use Log4j you will also need to place a <code class="filename">log4j.properties</code> file in your classpath. An example properties file is distributed with Hibernate in the <code class="literal">src/</code> directory. </p><p>It is recommended that you familiarize yourself with Hibernate's log messages. A lot of work has been put into making the Hibernate log as detailed as possible, without making it unreadable. It is an essential troubleshooting device. The most interesting log categories are the following: </p><div class="table"><a id="log-categories"/><p class="title"><b>表 3.9. Hibernate ログカテゴリ</b></p><div class="table-contents"><table summary="Hibernate ログカテゴリ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>カテゴリ</th><th>機能</th></tr></thead><tbody><tr><td><code class="literal">org.hibernate.SQL</code></td><td>実行したすべてのSQL(DDL)ステートメントをロギングします。</td></tr><tr><td><code class="literal">org.hibernate.type</code></td><td>すべてのJDBCパラメータをロギングします。</td></tr><tr><td><code class="literal">org.hibernate.tool.hbm2ddl</code></td><td>実行したすべてのSQL(DDL)ステートメントをロギングします。</td></tr><tr><td><code class="literal">org.hibernate.pretty</code></td><td>sessionに関連するすべてのエンティティ(最大20)のフラッシュ時間をロギングします。 </td></tr><tr><td><code class="literal">org.hibernate.cache</code></td><td>すべての2次キャッシュの動作をロギングします。</td></tr><tr><td><code class="literal">org.hibernate.transaction</code></td><td>トランザクションに関連する動作をロギングします。</td></tr><tr><td><code class="literal">org.hibernate.jdbc</code></td><td>JDBCリソース取得をロギングします。</td></tr><tr><td><code class="literal">org.hibernate.hql.ast.AST</code></td><td>HQLとSQLのASTのクエリーパースをロギングします。 </td></tr><tr><td><code class="literal">org.hibernate.secure</code></td><td>すべてのJAAS分析をロギングします。</td></tr><tr><td><code class="literal">org.hibernate</code></td><td>Log everything. This is a lot of information but it is useful for troubleshooting </td></tr></tbody></table></div></div><br class="table-break"/><p>Hibernateでアプリケーションを作成するときは、<code class="literal">org.hibernate.SQL</code> カテゴリの <code class="literal">debug</code> を常に有効にしておいたほうが良いでしょう。 代替方法として、<code class="literal">hibernate.show_sql</code> を有効にする方法があります。 </p></div><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-namingstrategy"/>3.6. <code class="literal">NamingStrategy</code> の実装</h2></div></div></div><p>インターフェイス <code class="literal">net.sf.hibernate.cfg.NamingStrategy</code> を使うと データベースオブジェクトとスキーマ要素のための「命名標準」を指定できます。 </p><p>You can provide rules for automatically generating database identifiers from Java identifiers or for processing "logical" column and table names given in the mapping file into "physical" table and column names. This feature helps reduce the verbosity of the mapping document, eliminating repetitive noise (<code class="literal">TBL_</code> prefixes, for example). The default strategy used by Hibernate is quite minimal. </p><p>You can specify a different strategy by calling <code class="literal">Configuration.setNamingStrategy()</code> before adding mappings: </p><pre class="programlisting">SessionFactory sf = new Configuration()
185
 
    .setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
186
 
    .addFile("Item.hbm.xml")
187
 
    .addFile("Bid.hbm.xml")
188
 
    .buildSessionFactory();</pre><p><code class="literal">org.hibernate.cfg.ImprovedNamingStrategy</code> は組み込みの戦略です。 これはいくつかのアプリケーションにとって有用な開始点となるかもしれません。 </p></div><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-xmlconfig"/>3.7. XML設定ファイル</h2></div></div></div><p>もう1つの方法は <code class="literal">hibernate.cfg.xml</code> という名前のファイルで 十分な設定を指定する方法です。 このファイルは <code class="literal">hibernate.properties</code> ファイルの代わりとなります。 もし両方のファイルがあれば、プロパティが置き換えられます。 </p><p>The XML configuration file is by default expected to be in the root of your <code class="literal">CLASSPATH</code>. Here is an example: </p><pre class="programlisting">&lt;?xml version='1.0' encoding='utf-8'?&gt;
189
 
&lt;!DOCTYPE hibernate-configuration PUBLIC
190
 
    "-//Hibernate/Hibernate Configuration DTD//EN"
191
 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
192
 
 
193
 
&lt;hibernate-configuration&gt;
194
 
 
195
 
    &lt;!-- a SessionFactory instance listed as /jndi/name --&gt;
196
 
    &lt;session-factory
197
 
        name="java:hibernate/SessionFactory"&gt;
198
 
 
199
 
        &lt;!-- properties --&gt;
200
 
        &lt;property name="connection.datasource"&gt;java:/comp/env/jdbc/MyDB&lt;/property&gt;
201
 
        &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
202
 
        &lt;property name="show_sql"&gt;false&lt;/property&gt;
203
 
        &lt;property name="transaction.factory_class"&gt;
204
 
            org.hibernate.transaction.JTATransactionFactory
205
 
        &lt;/property&gt;
206
 
        &lt;property name="jta.UserTransaction"&gt;java:comp/UserTransaction&lt;/property&gt;
207
 
 
208
 
        &lt;!-- mapping files --&gt;
209
 
        &lt;mapping resource="org/hibernate/auction/Item.hbm.xml"/&gt;
210
 
        &lt;mapping resource="org/hibernate/auction/Bid.hbm.xml"/&gt;
211
 
 
212
 
        &lt;!-- cache settings --&gt;
213
 
        &lt;class-cache class="org.hibernate.auction.Item" usage="read-write"/&gt;
214
 
        &lt;class-cache class="org.hibernate.auction.Bid" usage="read-only"/&gt;
215
 
        &lt;collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write"/&gt;
216
 
 
217
 
    &lt;/session-factory&gt;
218
 
 
219
 
&lt;/hibernate-configuration&gt;</pre><p>The advantage of this approach is the externalization of the mapping file names to configuration. The <code class="literal">hibernate.cfg.xml</code> is also more convenient once you have to tune the Hibernate cache. It is your choice to use either <code class="literal">hibernate.properties</code> or <code class="literal">hibernate.cfg.xml</code>. Both are equivalent, except for the above mentioned benefits of using the XML syntax. </p><p>With the XML configuration, starting Hibernate is then as simple as: </p><pre class="programlisting">SessionFactory sf = new Configuration().configure().buildSessionFactory();</pre><p>You can select a different XML configuration file using: </p><pre class="programlisting">SessionFactory sf = new Configuration()
220
 
    .configure("catdb.cfg.xml")
221
 
    .buildSessionFactory();</pre></div><div class="sect1" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-j2ee"/>3.8. J2EEアプリケーションサーバとの統合</h2></div></div></div><p>HibernateはJ2EE構造と統合するポイントをサポートしています。 </p><div class="itemizedlist"><ul><li><p><span class="emphasis"><em>Container-managed datasources</em></span>: Hibernate can use JDBC connections managed by the container and provided through JNDI. Usually, a JTA compatible <code class="literal">TransactionManager</code> and a <code class="literal">ResourceManager</code> take care of transaction management (CMT), especially distributed transaction handling across several datasources. You can also demarcate transaction boundaries programmatically (BMT), or you might want to use the optional Hibernate <code class="literal">Transaction</code> API for this to keep your code portable. </p></li></ul></div><div class="itemizedlist"><ul><li><p><span class="emphasis"><em>自動JNDIバインディング</em></span>:HibernateはJNDIが立ち上がった後に <code class="literal">SessionFactory</code> を生成します。 </p></li></ul></div><div class="itemizedlist"><ul><li><p><span class="emphasis"><em>JTA Session binding:</em></span> the Hibernate <code class="literal">Session</code> can be automatically bound to the scope of JTA transactions. Simply lookup the <code class="literal">SessionFactory</code> from JNDI and get the current <code class="literal">Session</code>. Let Hibernate manage flushing and closing the <code class="literal">Session</code> when your JTA transaction completes. Transaction demarcation is either declarative (CMT) or programmatic (BMT/UserTransaction). </p></li></ul></div><div class="itemizedlist"><ul><li><p><span class="emphasis"><em>JMX deployment:</em></span> if you have a JMX capable application server (e.g. JBoss AS), you can choose to deploy Hibernate as a managed MBean. This saves you the one line startup code to build your <code class="literal">SessionFactory</code> from a <code class="literal">Configuration</code>. The container will startup your <code class="literal">HibernateService</code> and also take care of service dependencies (datasource has to be available before Hibernate starts, etc). </p></li></ul></div><p>環境に依存しますが、もし、アプリケーションサーバが"connection containment"の例外をスローするなら 設定のオプション <code class="literal">hibernate.connection.aggressive_release</code> をtrueにしてください。 </p><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-transactionstrategy"/>3.8.1. トランザクション戦略設定</h3></div></div></div><p>The Hibernate <code class="literal">Session</code> API is independent of any transaction demarcation system in your architecture. If you let Hibernate use JDBC directly through a connection pool, you can begin and end your transactions by calling the JDBC API. If you run in a J2EE application server, you might want to use bean-managed transactions and call the JTA API and <code class="literal">UserTransaction</code> when needed. </p><p>2つ(それ以上)の環境で互換性のあるコードを維持するために、オプションとして根本的なシステムを ラッピングするHibernate <code class="literal">Transaction</code> APIを推奨します。 Hibernate設定プロパティの <code class="literal">hibernate.transaction.factory_class</code> を設定することで ある特定の <code class="literal">Transaction</code> クラスのインスタンスを持つことができます。 </p><p>There are three standard, or built-in, choices: </p><div class="variablelist"><dl><dt><span class="term"><code class="literal">org.hibernate.transaction.JDBCTransactionFactory</code></span></dt><dd><p>データベース(JDBC)トランザクションに委譲します(デフォルト)</p></dd><dt><span class="term"><code class="literal">org.hibernate.transaction.JTATransactionFactory</code></span></dt><dd><p>delegates to container-managed transactions if an existing transaction is underway in this context (for example, EJB session bean method). Otherwise, a new transaction is started and bean-managed transactions are used. </p></dd><dt><span class="term"><code class="literal">org.hibernate.transaction.CMTTransactionFactory</code></span></dt><dd><p>コンテナ管理JTAトランザクションに委譲します</p></dd></dl></div><p>You can also define your own transaction strategies (for a CORBA transaction service, for example). </p><p>Some features in Hibernate (i.e., the second level cache, Contextual Sessions with JTA, etc.) require access to the JTA <code class="literal">TransactionManager</code> in a managed environment. In an application server, since J2EE does not standardize a single mechanism, you have to specify how Hibernate should obtain a reference to the <code class="literal">TransactionManager</code>: </p><div class="table"><a id="jtamanagerlookup"/><p class="title"><b>表 3.10. JTA トランザクションマネージャ</b></p><div class="table-contents"><table summary="JTA トランザクションマネージャ" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>Transaction Factory</th><th align="center">Application Server</th></tr></thead><tbody><tr><td><code class="literal">org.hibernate.transaction.JBossTransactionManagerLookup</code></td><td align="center">JBoss</td></tr><tr><td><code class="literal">org.hibernate.transaction.WeblogicTransactionManagerLookup</code></td><td align="center">Weblogic</td></tr><tr><td><code class="literal">org.hibernate.transaction.WebSphereTransactionManagerLookup</code></td><td align="center">WebSphere</td></tr><tr><td><code class="literal">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</code></td><td align="center">WebSphere 6</td></tr><tr><td><code class="literal">org.hibernate.transaction.OrionTransactionManagerLookup</code></td><td align="center">Orion</td></tr><tr><td><code class="literal">org.hibernate.transaction.ResinTransactionManagerLookup</code></td><td align="center">Resin</td></tr><tr><td><code class="literal">org.hibernate.transaction.JOTMTransactionManagerLookup</code></td><td align="center">JOTM</td></tr><tr><td><code class="literal">org.hibernate.transaction.JOnASTransactionManagerLookup</code></td><td align="center">JOnAS</td></tr><tr><td><code class="literal">org.hibernate.transaction.JRun4TransactionManagerLookup</code></td><td align="center">JRun4</td></tr><tr><td><code class="literal">org.hibernate.transaction.BESTransactionManagerLookup</code></td><td align="center">Borland ES</td></tr></tbody></table></div></div><br class="table-break"/></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-jndi"/>3.8.2. <code class="literal">SessionFactory</code> のJNDIへの登録</h3></div></div></div><p>A JNDI-bound Hibernate <code class="literal">SessionFactory</code> can simplify the lookup function of the factory and create new <code class="literal">Session</code>s. This is not, however, related to a JNDI bound <code class="literal">Datasource</code>; both simply use the same registry. </p><p>If you wish to have the <code class="literal">SessionFactory</code> bound to a JNDI namespace, specify a name (e.g. <code class="literal">java:hibernate/SessionFactory</code>) using the property <code class="literal">hibernate.session_factory_name</code>. If this property is omitted, the <code class="literal">SessionFactory</code> will not be bound to JNDI. This is especially useful in environments with a read-only JNDI default implementation (in Tomcat, for example). </p><p><code class="literal">SessionFactory</code> をJNDIに登録するとき、Hibernateは <code class="literal">hibernate.jndi.url</code> の値を使用し、<code class="literal">hibernate.jndi.class</code> をイニシャルコンテキストとして具体化します。 もし何も設定しない場合は、デフォルトの <code class="literal">InitialContext</code> を使用します。 </p><p>Hibernate will automatically place the <code class="literal">SessionFactory</code> in JNDI after you call <code class="literal">cfg.buildSessionFactory()</code>. This means you will have this call in some startup code, or utility class in your application, unless you use JMX deployment with the <code class="literal">HibernateService</code> (this is discussed later in greater detail). </p><p>If you use a JNDI <code class="literal">SessionFactory</code>, an EJB or any other class, you can obtain the <code class="literal">SessionFactory</code> using a JNDI lookup. </p><p>It is recommended that you bind the <code class="literal">SessionFactory</code> to JNDI in a managed environment and use a <code class="literal">static</code> singleton otherwise. To shield your application code from these details, we also recommend to hide the actual lookup code for a <code class="literal">SessionFactory</code> in a helper class, such as <code class="literal">HibernateUtil.getSessionFactory()</code>. Note that such a class is also a convenient way to startup Hibernatesee chapter 1. </p></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-j2ee-currentsession"/>3.8.3. JTAによる現在のセッションコンテキストマネージメント</h3></div></div></div><p>The easiest way to handle <code class="literal">Sessions</code> and transactions is Hibernate's automatic "current" <code class="literal">Session</code> management. For a discussion of contextual sessions see <a href="architecture.html#architecture-current-session" title="2.5. Contextual sessions">項2.5. 「Contextual sessions」</a>. Using the <code class="literal">"jta"</code> session context, if there is no Hibernate <code class="literal">Session</code> associated with the current JTA transaction, one will be started and associated with that JTA transaction the first time you call <code class="literal">sessionFactory.getCurrentSession()</code>. The <code class="literal">Session</code>s retrieved via <code class="literal">getCurrentSession()</code> in the<code class="literal">"jta"</code> context are set to automatically flush before the transaction completes, close after the transaction completes, and aggressively release JDBC connections after each statement. This allows the <code class="literal">Session</code>s to be managed by the life cycle of the JTA transaction to which it is associated, keeping user code clean of such management concerns. Your code can either use JTA programmatically through <code class="literal">UserTransaction</code>, or (recommended for portable code) use the Hibernate <code class="literal">Transaction</code> API to set transaction boundaries. If you run in an EJB container, declarative transaction demarcation with CMT is preferred. </p></div><div class="sect2" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-j2ee-jmx"/>3.8.4. JMXデプロイメント</h3></div></div></div><p>The line <code class="literal">cfg.buildSessionFactory()</code> still has to be executed somewhere to get a <code class="literal">SessionFactory</code> into JNDI. You can do this either in a <code class="literal">static</code> initializer block, like the one in <code class="literal">HibernateUtil</code>, or you can deploy Hibernate as a <span class="emphasis"><em>managed service</em></span>. </p><p>Hibernate is distributed with <code class="literal">org.hibernate.jmx.HibernateService</code> for deployment on an application server with JMX capabilities, such as JBoss AS. The actual deployment and configuration is vendor-specific. Here is an example <code class="literal">jboss-service.xml</code> for JBoss 4.0.x: </p><pre class="programlisting">&lt;?xml version="1.0"?&gt;
222
 
&lt;server&gt;
223
 
 
224
 
&lt;mbean code="org.hibernate.jmx.HibernateService"
225
 
    name="jboss.jca:service=HibernateFactory,name=HibernateFactory"&gt;
226
 
 
227
 
    &lt;!-- Required services --&gt;
228
 
    &lt;depends&gt;jboss.jca:service=RARDeployer&lt;/depends&gt;
229
 
    &lt;depends&gt;jboss.jca:service=LocalTxCM,name=HsqlDS&lt;/depends&gt;
230
 
 
231
 
    &lt;!-- Bind the Hibernate service to JNDI --&gt;
232
 
    &lt;attribute name="JndiName"&gt;java:/hibernate/SessionFactory&lt;/attribute&gt;
233
 
 
234
 
    &lt;!-- Datasource settings --&gt;
235
 
    &lt;attribute name="Datasource"&gt;java:HsqlDS&lt;/attribute&gt;
236
 
    &lt;attribute name="Dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/attribute&gt;
237
 
 
238
 
    &lt;!-- Transaction integration --&gt;
239
 
    &lt;attribute name="TransactionStrategy"&gt;
240
 
        org.hibernate.transaction.JTATransactionFactory&lt;/attribute&gt;
241
 
    &lt;attribute name="TransactionManagerLookupStrategy"&gt;
242
 
        org.hibernate.transaction.JBossTransactionManagerLookup&lt;/attribute&gt;
243
 
    &lt;attribute name="FlushBeforeCompletionEnabled"&gt;true&lt;/attribute&gt;
244
 
    &lt;attribute name="AutoCloseSessionEnabled"&gt;true&lt;/attribute&gt;
245
 
 
246
 
    &lt;!-- Fetching options --&gt;
247
 
    &lt;attribute name="MaximumFetchDepth"&gt;5&lt;/attribute&gt;
248
 
 
249
 
    &lt;!-- Second-level caching --&gt;
250
 
    &lt;attribute name="SecondLevelCacheEnabled"&gt;true&lt;/attribute&gt;
251
 
    &lt;attribute name="CacheProviderClass"&gt;org.hibernate.cache.EhCacheProvider&lt;/attribute&gt;
252
 
    &lt;attribute name="QueryCacheEnabled"&gt;true&lt;/attribute&gt;
253
 
 
254
 
    &lt;!-- Logging --&gt;
255
 
    &lt;attribute name="ShowSqlEnabled"&gt;true&lt;/attribute&gt;
256
 
 
257
 
    &lt;!-- Mapping files --&gt;
258
 
    &lt;attribute name="MapResources"&gt;auction/Item.hbm.xml,auction/Category.hbm.xml&lt;/attribute&gt;
259
 
 
260
 
&lt;/mbean&gt;
261
 
 
262
 
&lt;/server&gt;</pre><p>This file is deployed in a directory called <code class="literal">META-INF</code> and packaged in a JAR file with the extension <code class="literal">.sar</code> (service archive). You also need to package Hibernate, its required third-party libraries, your compiled persistent classes, as well as your mapping files in the same archive. Your enterprise beans (usually session beans) can be kept in their own JAR file, but you can include this EJB JAR file in the main service archive to get a single (hot-)deployable unit. Consult the JBoss AS documentation for more information about JMX service and EJB deployment. </p></div></div></div><HR xmlns=""/><a xmlns="" href="legalnotice.html"><p xmlns="http://www.w3.org/1999/xhtml" class="copyright">製作著作 © 2004 Red Hat Middleware, LLC.</p></a><ul class="docnav"><li class="previous"><a accesskey="p" href="architecture.html"><strong>前のページ</strong>第2章 アーキテクチャ</a></li><li class="up"><a accesskey="u" href="#"><strong>上に戻る</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>ホーム</strong></a></li><li class="next"><a accesskey="n" href="persistent-classes.html"><strong>次のページ</strong>第4章 永続クラス</a></li></ul></body></html>
 
 
b'\\ No newline at end of file'