~raginggoblin/infolog/infolog

« back to all changes in this revision

Viewing changes to InfologServer/lib/hibernate-distribution-3.3.2.GA/documentation/manual/ko-KR/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 - 개성있는 자바를 위한 관계 영속"/><link rel="up" href="index.html" title="HIBERNATE - 개성있는 자바를 위한 관계 영속"/><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="ko-KR"><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 Dialects</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-outerjoin">3.4.2. Outer Join Fetching</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-binarystreams">3.4.3. Binary Streams</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-cacheprovider">3.4.4. Second-level 캐시와 query 캐시</a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-optional-querysubstitution">3.4.5. Query Language 치환</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. JNDI-bound <code class="literal">SessionFactory</code></a></span></dt><dt><span class="sect2"><a href="session-configuration.html#configuration-j2ee-currentsession">3.8.3. Current Session context management with 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="ko-KR"><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">java -Dproperty=value</code>를 사용하여 <code class="literal">System</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="ko-KR"><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="ko-KR"><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="d0e1747"/><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>데이터베이스 사용자</em></span>
25
 
                </td></tr><tr><td>
26
 
                    <span class="property">hibernate.connection.password</span>
27
 
                </td><td>
28
 
                    <span class="emphasis"><em>데이터베이스 사용자 패스워드</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="d0e1849"/><p class="title"><b>표 3.2. Hibernate Datasource Properties</b></p><div class="table-contents"><table summary="Hibernate Datasource Properties" 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 datasource로부터 얻어진 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="ko-KR"><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 Cache 프로퍼티들</b></p><div class="table-contents"><table summary="Hibernate Cache 프로퍼티들" 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="ko-KR"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-dialects"/>3.4.1. SQL Dialects</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="ko-KR"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-outerjoin"/>3.4.2. Outer Join Fetching</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>추가 정보는 <a href="performance.html#performance-fetching" title="19.1. 페칭 방도들">19.1절. “페칭 방도들”</a>를 보라. </p></div><div class="sect2" lang="ko-KR"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-binarystreams"/>3.4.3. Binary Streams</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="ko-KR"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-cacheprovider"/>3.4.4. Second-level 캐시와 query 캐시</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. 두번째 레벨 캐시">19.2절. “두번째 레벨 캐시”</a> for more information. </p></div><div class="sect2" lang="ko-KR"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-querysubstitution"/>3.4.5. Query Language 치환</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="ko-KR"><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="ko-KR"><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 DML 문장들이 실행될 때 그것들 모두를 로그 시킨다</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>flush 시점에서 세션과 연관된 모든 엔티티들(최대 20개의 엔티티들)의 상태를 로그 시킨다 </td></tr><tr><td><code class="literal">org.hibernate.cache</code></td><td>모든 second-level 캐시 액티비티를 로그시킨다</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 AST와 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="ko-KR"><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">org.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="ko-KR"><div class="titlepage"><div><div><h2 class="title"><a id="configuration-xmlconfig"/>3.7. XML 구성 파일</h2></div></div></div><p>구성에 대한 다른 접근법은 <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="ko-KR"><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는 시작 후에 그것의 <code class="literal">SessionFactory</code>를 JNDI에 바인드 시킬 수 있다. </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="ko-KR"><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>이들 두 개의 (그리고 다른) 환경들에서 당신의 코드에 이식성을 유지하기 위해 우리는 기본 시스템을 포장하고 은폐시키는 선택적인 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>container-managed 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 TransactionManagers</b></p><div class="table-contents"><table summary="JTA TransactionManagers" border="1"><colgroup><col/><col/></colgroup><thead><tr><th>트랜잭션 팩토리</th><th align="center">어플리케이션 서버</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="ko-KR"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-optional-jndi"/>3.8.2. JNDI-bound <code class="literal">SessionFactory</code></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="ko-KR"><div class="titlepage"><div><div><h3 class="title"><a id="configuration-j2ee-currentsession"/>3.8.3. Current Session context management with 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="ko-KR"><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'