/
configuration.xml
1806 lines (1405 loc) · 71.8 KB
/
configuration.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<chapter xml:id="session-configuration" revision="1" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Configuration</title>
<para>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 <literal>hibernate.properties</literal> file in
<literal>etc/</literal> that displays the various options. Simply put the
example file in your classpath and customize it to suit your needs.</para>
<section xml:id="configuration-programmatic" revision="1">
<title>Programmatic configuration</title>
<para>An instance of
<classname>org.hibernate.cfg.Configuration</classname> represents an
entire set of mappings of an application's Java types to an SQL database.
The <classname>org.hibernate.cfg.Configuration</classname> is used to
build an immutable
<interfacename>org.hibernate.SessionFactory</interfacename>. The mappings
are compiled from various XML mapping files.</para>
<para>You can obtain a
<classname>org.hibernate.cfg.Configuration</classname> instance by
instantiating it directly and specifying XML mapping documents. If the
mapping files are in the classpath, use <literal>addResource()</literal>.
For example:</para>
<programlisting role="JAVA">Configuration cfg = new Configuration()
.addResource("Item.hbm.xml")
.addResource("Bid.hbm.xml");</programlisting>
<para>An alternative way is to specify the mapped class and allow
Hibernate to find the mapping document for you:</para>
<programlisting role="JAVA">Configuration cfg = new Configuration()
.addClass(org.hibernate.auction.Item.class)
.addClass(org.hibernate.auction.Bid.class);</programlisting>
<para>Hibernate will then search for mapping files named
<filename>/org/hibernate/auction/Item.hbm.xml</filename> and
<filename>/org/hibernate/auction/Bid.hbm.xml</filename> in the classpath.
This approach eliminates any hardcoded filenames.</para>
<para>A <classname>org.hibernate.cfg.Configuration</classname> also allows
you to specify configuration properties. For example:</para>
<programlisting role="JAVA">Configuration cfg = new Configuration()
.addClass(org.hibernate.auction.Item.class)
.addClass(org.hibernate.auction.Bid.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
.setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test")
.setProperty("hibernate.order_updates", "true");</programlisting>
<para>This is not the only way to pass configuration properties to
Hibernate. Some alternative options include:</para>
<orderedlist spacing="compact">
<listitem>
<para>Pass an instance of <classname>java.util.Properties</classname>
to <literal>Configuration.setProperties()</literal>.</para>
</listitem>
<listitem>
<para>Place a file named <filename>hibernate.properties</filename> in
a root directory of the classpath.</para>
</listitem>
<listitem>
<para>Set <literal>System</literal> properties using <literal>java
-Dproperty=value</literal>.</para>
</listitem>
<listitem>
<para>Include <literal><property></literal> elements in
<literal>hibernate.cfg.xml</literal> (this is discussed later).</para>
</listitem>
</orderedlist>
<para>If you want to get started
quickly<filename>hibernate.properties</filename> is the easiest
approach.</para>
<para>The <classname>org.hibernate.cfg.Configuration</classname> is
intended as a startup-time object that will be discarded once a
<literal>SessionFactory</literal> is created.</para>
</section>
<section xml:id="configuration-sessionfactory">
<title>Obtaining a SessionFactory</title>
<para>When all mappings have been parsed by the
<classname>org.hibernate.cfg.Configuration</classname>, the application
must obtain a factory for
<interfacename>org.hibernate.Session</interfacename> instances. This
factory is intended to be shared by all application threads:</para>
<programlisting role="JAVA">SessionFactory sessions = cfg.buildSessionFactory();</programlisting>
<para>Hibernate does allow your application to instantiate more than one
<interfacename>org.hibernate.SessionFactory</interfacename>. This is
useful if you are using more than one database.</para>
</section>
<section xml:id="configuration-hibernatejdbc" revision="1">
<title>JDBC connections</title>
<para>It is advisable to have the
<interfacename>org.hibernate.SessionFactory</interfacename> create and
pool JDBC connections for you. If you take this approach, opening a
<interfacename>org.hibernate.Session</interfacename> is as simple
as:</para>
<programlisting role="JAVA">Session session = sessions.openSession(); // open a new Session</programlisting>
<para>Once you start a task that requires access to the database, a JDBC
connection will be obtained from the pool.</para>
<para>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 <classname>org.hibernate.cfg.Environment</classname>.
The most important settings for JDBC connection configuration are outlined
below.</para>
<para>Hibernate will obtain and pool connections using
<classname>java.sql.DriverManager</classname> if you set the following
properties:</para>
<table frame="topbot">
<title>Hibernate JDBC Properties</title>
<tgroup cols="2">
<colspec colname="c1" colwidth="1*" />
<colspec colname="c2" colwidth="1*" />
<thead>
<row>
<entry>Property name</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><property>hibernate.connection.driver_class</property></entry>
<entry><emphasis>JDBC driver class</emphasis></entry>
</row>
<row>
<entry><property>hibernate.connection.url</property></entry>
<entry><emphasis>JDBC URL</emphasis></entry>
</row>
<row>
<entry><property>hibernate.connection.username</property></entry>
<entry><emphasis>database user</emphasis></entry>
</row>
<row>
<entry><property>hibernate.connection.password</property></entry>
<entry><emphasis>database user password</emphasis></entry>
</row>
<row>
<entry><property>hibernate.connection.pool_size</property></entry>
<entry><emphasis>maximum number of pooled
connections</emphasis></entry>
</row>
</tbody>
</tgroup>
</table>
<para>Hibernate's own connection pooling algorithm is, however, quite
rudimentary. It is intended to help you get started and is <emphasis>not
intended for use in a production system</emphasis>, or even for
performance testing. You should use a third party pool for best
performance and stability. Just replace the
<property>hibernate.connection.pool_size</property> property with
connection pool specific settings. This will turn off Hibernate's internal
pool. For example, you might like to use c3p0.</para>
<para>C3P0 is an open source JDBC connection pool distributed along with
Hibernate in the <filename>lib</filename> directory. Hibernate will use
its <classname>org.hibernate.connection.C3P0ConnectionProvider</classname>
for connection pooling if you set <property>hibernate.c3p0.*</property>
properties. If you would like to use Proxool, refer to the packaged
<filename>hibernate.properties</filename> and the Hibernate web site for
more information.</para>
<para>The following is an example
<filename>hibernate.properties</filename> file for c3p0:</para>
<programlisting>hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect</programlisting>
<para>For use inside an application server, you should almost always
configure Hibernate to obtain connections from an application server
<interfacename>javax.sql.Datasource</interfacename> registered in JNDI.
You will need to set at least one of the following properties:</para>
<table frame="topbot">
<title>Hibernate Datasource Properties</title>
<tgroup cols="2">
<colspec colname="c1" colwidth="1*" />
<colspec colname="c2" colwidth="1*" />
<thead>
<row>
<entry>Property name</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><property>hibernate.connection.datasource</property></entry>
<entry><emphasis>datasource JNDI name</emphasis></entry>
</row>
<row>
<entry><property>hibernate.jndi.url</property></entry>
<entry><emphasis>URL of the JNDI provider</emphasis>
(optional)</entry>
</row>
<row>
<entry><property>hibernate.jndi.class</property></entry>
<entry><emphasis>class of the JNDI
<literal>InitialContextFactory</literal></emphasis>
(optional)</entry>
</row>
<row>
<entry><property>hibernate.connection.username</property></entry>
<entry><emphasis>database user</emphasis> (optional)</entry>
</row>
<row>
<entry><property>hibernate.connection.password</property></entry>
<entry><emphasis>database user password</emphasis>
(optional)</entry>
</row>
</tbody>
</tgroup>
</table>
<para>Here is an example <filename>hibernate.properties</filename> file
for an application server provided JNDI datasource:</para>
<programlisting>hibernate.connection.datasource = java:/comp/env/jdbc/test
hibernate.transaction.factory_class = \
org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = \
org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.PostgreSQL82Dialect</programlisting>
<para>JDBC connections obtained from a JNDI datasource will automatically
participate in the container-managed transactions of the application
server.</para>
<para>Arbitrary connection properties can be given by prepending
"<literal>hibernate.connection</literal>" to the connection property name.
For example, you can specify a <property>charSet</property> connection
property using <property>hibernate.connection.charSet</property>.</para>
<para>You can define your own plugin strategy for obtaining JDBC
connections by implementing the interface
<interfacename>org.hibernate.connection.ConnectionProvider</interfacename>,
and specifying your custom implementation via the
<property>hibernate.connection.provider_class</property> property.</para>
</section>
<section xml:id="configuration-optional" revision="1">
<title>Optional configuration properties</title>
<para>There are a number of other properties that control the behavior of
Hibernate at runtime. All are optional and have reasonable default
values.</para>
<para><warning>
<para><emphasis>Some of these properties are "system-level"
only.</emphasis> System-level properties can be set only via
<literal>java -Dproperty=value</literal> or
<filename>hibernate.properties</filename>. They
<emphasis>cannot</emphasis> be set by the other techniques described
above.</para>
</warning></para>
<table frame="topbot" xml:id="configuration-optional-properties" revision="8">
<title>Hibernate Configuration Properties</title>
<tgroup cols="2">
<colspec colname="c1" colwidth="1*" />
<colspec colname="c2" colwidth="1*" />
<thead>
<row>
<entry>Property name</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><property>hibernate.dialect</property></entry>
<entry>The classname of a Hibernate
<classname>org.hibernate.dialect.Dialect</classname> which allows
Hibernate to generate SQL optimized for a particular relational
database. <para> <emphasis role="strong">e.g.</emphasis>
<literal>full.classname.of.Dialect</literal> </para> <para> In
most cases Hibernate will actually be able to choose the correct
<classname>org.hibernate.dialect.Dialect</classname>
implementation based on the <literal>JDBC metadata</literal>
returned by the JDBC driver. </para></entry>
</row>
<row>
<entry><property>hibernate.show_sql</property></entry>
<entry>Write all SQL statements to console. This is an alternative
to setting the log category <literal>org.hibernate.SQL</literal>
to <literal>debug</literal>. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.format_sql</property></entry>
<entry>Pretty print the SQL in the log and console. <para>
<emphasis role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.default_schema</property></entry>
<entry>Qualify unqualified table names with the given
schema/tablespace in generated SQL. <para> <emphasis
role="strong">e.g.</emphasis> <literal>SCHEMA_NAME</literal>
</para></entry>
</row>
<row>
<entry><property>hibernate.default_catalog</property></entry>
<entry>Qualifies unqualified table names with the given catalog in
generated SQL. <para> <emphasis role="strong">e.g.</emphasis>
<literal>CATALOG_NAME</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.session_factory_name</property></entry>
<entry>The
<interfacename>org.hibernate.SessionFactory</interfacename> will
be automatically bound to this name in JNDI after it has been
created. <para> <emphasis role="strong">e.g.</emphasis>
<literal>jndi/composite/name</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.max_fetch_depth</property></entry>
<entry>Sets a maximum "depth" for the outer join fetch tree for
single-ended associations (one-to-one, many-to-one). A
<literal>0</literal> disables default outer join fetching. <para>
<emphasis role="strong">e.g.</emphasis> recommended values between
<literal>0</literal> and <literal>3</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.default_batch_fetch_size</property></entry>
<entry>Sets a default size for Hibernate batch fetching of
associations. <para> <emphasis role="strong">e.g.</emphasis>
recommended values <literal>4</literal>, <literal>8</literal>,
<literal>16</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.default_entity_mode</property></entry>
<entry>Sets a default mode for entity representation for all
sessions opened from this <literal>SessionFactory</literal> <para>
<literal>dynamic-map</literal>, <literal>dom4j</literal>,
<literal>pojo</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.order_updates</property></entry>
<entry>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. <para>
<emphasis role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.generate_statistics</property></entry>
<entry>If enabled, Hibernate will collect statistics useful for
performance tuning. <para> <emphasis role="strong">e.g.</emphasis>
<literal>true</literal> | <literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.use_identifier_rollback</property></entry>
<entry>If enabled, generated identifier properties will be reset
to default values when objects are deleted. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.use_sql_comments</property></entry>
<entry>If turned on, Hibernate will generate comments inside the
SQL, for easier debugging, defaults to <literal>false</literal>.
<para> <emphasis role="strong">e.g.</emphasis>
<literal>true</literal> | <literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.id.new_generator_mappings</property></entry>
<entry>Setting is relevant when using
<classname>@GeneratedValue</classname>. It indicates whether or
not the new <classname>IdentifierGenerator</classname>
implementations are used for
<classname>javax.persistence.GenerationType.AUTO</classname>,
<classname>javax.persistence.GenerationType.TABLE</classname> and
<classname>javax.persistence.GenerationType.SEQUENCE</classname>.
Default to <literal>false</literal> to keep backward
compatibility. <para> <emphasis role="strong">e.g.</emphasis>
<literal>true</literal> | <literal>false</literal> </para></entry>
</row>
</tbody>
</tgroup>
</table>
<note>
<para>We recommend all new projects which make use of to use
<classname>@GeneratedValue</classname> to also set
<code>hibernate.id.new_generator_mappings=true</code> as the new
generators are more efficient and closer to the JPA 2 specification
semantic. However they are not backward compatible with existing
databases (if a sequence or a table is used for id generation).</para>
</note>
<table frame="topbot" xml:id="configuration-jdbc-properties" revision="8">
<title>Hibernate JDBC and Connection Properties</title>
<tgroup cols="2">
<!--
<colspec colname="c1" colwidth="1*"/>
<colspec colname="c2" colwidth="1*"/>
-->
<thead>
<row>
<entry>Property name</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><property>hibernate.jdbc.fetch_size</property></entry>
<entry>A non-zero value determines the JDBC fetch size (calls
<literal>Statement.setFetchSize()</literal>).</entry>
</row>
<row>
<entry><property>hibernate.jdbc.batch_size</property></entry>
<entry>A non-zero value enables use of JDBC2 batch updates by
Hibernate. <para> <emphasis role="strong">e.g.</emphasis>
recommended values between <literal>5</literal> and
<literal>30</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.jdbc.batch_versioned_data</property></entry>
<entry>Set this property to <literal>true</literal> if your JDBC
driver returns correct row counts from
<literal>executeBatch()</literal>. It is usually safe to turn this
option on. Hibernate will then use batched DML for automatically
versioned data. Defaults to <literal>false</literal>. <para>
<emphasis role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.jdbc.factory_class</property></entry>
<entry>Select a custom
<interfacename>org.hibernate.jdbc.Batcher</interfacename>. Most
applications will not need this configuration property. <para>
<emphasis role="strong">e.g.</emphasis>
<literal>classname.of.BatcherFactory</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.jdbc.use_scrollable_resultset</property></entry>
<entry>Enables use of JDBC2 scrollable resultsets by Hibernate.
This property is only necessary when using user-supplied JDBC
connections. Hibernate uses connection metadata otherwise. <para>
<emphasis role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.jdbc.use_streams_for_binary</property></entry>
<entry>Use streams when writing/reading <literal>binary</literal>
or <literal>serializable</literal> types to/from JDBC.
<emphasis>*system-level property*</emphasis> <para> <emphasis
role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.jdbc.use_get_generated_keys</property></entry>
<entry>Enables use of JDBC3
<literal>PreparedStatement.getGeneratedKeys()</literal> 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.
<para> <emphasis role="strong">e.g.</emphasis>
<literal>true|false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.connection.provider_class</property></entry>
<entry>The classname of a custom
<interfacename>org.hibernate.connection.ConnectionProvider</interfacename>
which provides JDBC connections to Hibernate. <para> <emphasis
role="strong">e.g.</emphasis>
<literal>classname.of.ConnectionProvider</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.connection.isolation</property></entry>
<entry>Sets the JDBC transaction isolation level. Check
<interfacename>java.sql.Connection</interfacename> for meaningful
values, but note that most databases do not support all isolation
levels and some define additional, non-standard isolations. <para>
<emphasis role="strong">e.g.</emphasis> <literal>1, 2, 4,
8</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.connection.autocommit</property></entry>
<entry>Enables autocommit for JDBC pooled connections (it is not
recommended). <para> <emphasis role="strong">e.g.</emphasis>
<literal>true</literal> | <literal>false</literal> </para></entry>
</row>
<row>
<entry><property>hibernate.connection.release_mode</property></entry>
<entry>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 <literal>after_statement</literal> 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
<literal>after_transaction</literal>. <literal>auto</literal> will
choose <literal>after_statement</literal> for the JTA and CMT
transaction strategies and <literal>after_transaction</literal>
for the JDBC transaction strategy. <para> <emphasis
role="strong">e.g.</emphasis> <literal>auto</literal> (default) |
<literal>on_close</literal> | <literal>after_transaction</literal>
| <literal>after_statement</literal> </para> <para> This setting
only affects <literal>Session</literal>s returned from
<literal>SessionFactory.openSession</literal>. For
<literal>Session</literal>s obtained through
<literal>SessionFactory.getCurrentSession</literal>, the
<literal>CurrentSessionContext</literal> implementation configured
for use controls the connection release mode for those
<literal>Session</literal>s. See <xref
linkend="architecture-current-session" /> </para></entry>
</row>
<row>
<entry><property>hibernate.connection.</property><emphasis><propertyName></emphasis></entry>
<entry>Pass the JDBC property
<emphasis><propertyName></emphasis> to
<literal>DriverManager.getConnection()</literal>.</entry>
</row>
<row>
<entry><property>hibernate.jndi.</property><emphasis><propertyName></emphasis></entry>
<entry>Pass the property <emphasis><propertyName></emphasis>
to the JNDI <literal>InitialContextFactory</literal>.</entry>
</row>
</tbody>
</tgroup>
</table>
<table frame="topbot" xml:id="configuration-cache-properties" revision="7">
<title>Hibernate Cache Properties</title>
<tgroup cols="2">
<colspec colname="c1" colwidth="1*" />
<colspec colname="c2" colwidth="1*" />
<thead>
<row>
<entry>Property name</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>hibernate.cache.provider_class</literal></entry>
<entry>The classname of a custom <literal>CacheProvider</literal>.
<para> <emphasis role="strong">e.g.</emphasis>
<literal>classname.of.CacheProvider</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.cache.use_minimal_puts</literal></entry>
<entry>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. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true|false</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.cache.use_query_cache</literal></entry>
<entry>Enables the query cache. Individual queries still have to
be set cachable. <para> <emphasis role="strong">e.g.</emphasis>
<literal>true|false</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.cache.use_second_level_cache</literal></entry>
<entry>Can be used to completely disable the second level cache,
which is enabled by default for classes which specify a
<literal><cache></literal> mapping. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true|false</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.cache.query_cache_factory</literal></entry>
<entry>The classname of a custom <literal>QueryCache</literal>
interface, defaults to the built-in
<literal>StandardQueryCache</literal>. <para> <emphasis
role="strong">e.g.</emphasis>
<literal>classname.of.QueryCache</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.cache.region_prefix</literal></entry>
<entry>A prefix to use for second-level cache region names. <para>
<emphasis role="strong">e.g.</emphasis> <literal>prefix</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.cache.use_structured_entries</literal></entry>
<entry>Forces Hibernate to store data in the second-level cache in
a more human-friendly format. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true|false</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.cache.default_cache_concurrency_strategy</literal></entry>
<entry>Setting used to give the name of the default
<classname>org.hibernate.annotations.CacheConcurrencyStrategy</classname>
to use when either <classname>@Cacheable</classname> or
<classname>@Cache</classname> is used.
<code>@Cache(strategy="..")</code> is used to override this
default.</entry>
</row>
</tbody>
</tgroup>
</table>
<table frame="topbot" xml:id="configuration-transaction-properties"
revision="9">
<title>Hibernate Transaction Properties</title>
<tgroup cols="2">
<colspec colname="c1" colwidth="1*" />
<colspec colname="c2" colwidth="1*" />
<thead>
<row>
<entry>Property name</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>hibernate.transaction.factory_class</literal></entry>
<entry>The classname of a <literal>TransactionFactory</literal> to
use with Hibernate <literal>Transaction</literal> API (defaults to
<literal>JDBCTransactionFactory</literal>). <para> <emphasis
role="strong">e.g.</emphasis>
<literal>classname.of.TransactionFactory</literal> </para></entry>
</row>
<row>
<entry><literal>jta.UserTransaction</literal></entry>
<entry>A JNDI name used by
<literal>JTATransactionFactory</literal> to obtain the JTA
<literal>UserTransaction</literal> from the application server.
<para> <emphasis role="strong">e.g.</emphasis>
<literal>jndi/composite/name</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.transaction.manager_lookup_class</literal></entry>
<entry>The classname of a
<literal>TransactionManagerLookup</literal>. It is required when
JVM-level caching is enabled or when using hilo generator in a JTA
environment. <para> <emphasis role="strong">e.g.</emphasis>
<literal>classname.of.TransactionManagerLookup</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.transaction.flush_before_completion</literal></entry>
<entry>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 <xref
linkend="architecture-current-session" />. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.transaction.auto_close_session</literal></entry>
<entry>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 <xref
linkend="architecture-current-session" />. <para> <emphasis
role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
</tbody>
</tgroup>
</table>
<table frame="topbot" xml:id="configuration-misc-properties" revision="11">
<title>Miscellaneous Properties</title>
<tgroup cols="2">
<colspec colname="c1" colwidth="1*" />
<colspec colname="c2" colwidth="1*" />
<thead>
<row>
<entry>Property name</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>hibernate.current_session_context_class</literal></entry>
<entry>Supply a custom strategy for the scoping of the "current"
<literal>Session</literal>. See <xref
linkend="architecture-current-session" /> for more information
about the built-in strategies. <para> <emphasis
role="strong">e.g.</emphasis> <literal>jta</literal> |
<literal>thread</literal> | <literal>managed</literal> |
<literal>custom.Class</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.query.factory_class</literal></entry>
<entry>Chooses the HQL parser implementation. <para> <emphasis
role="strong">e.g.</emphasis>
<literal>org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory</literal>
or
<literal>org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.query.substitutions</literal></entry>
<entry>Is used to map from tokens in Hibernate queries to SQL
tokens (tokens might be function or literal names, for example).
<para> <emphasis role="strong">e.g.</emphasis>
<literal>hqlLiteral=SQL_LITERAL, hqlFunction=SQLFUNC</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.hbm2ddl.auto</literal></entry>
<entry>Automatically validates or exports schema DDL to the
database when the <literal>SessionFactory</literal> is created.
With <literal>create-drop</literal>, the database schema will be
dropped when the <literal>SessionFactory</literal> is closed
explicitly. <para> <emphasis role="strong">e.g.</emphasis>
<literal>validate</literal> | <literal>update</literal> |
<literal>create</literal> | <literal>create-drop</literal>
</para></entry>
</row>
<row>
<entry><literal>hibernate.hbm2ddl.import_files</literal></entry>
<entry><para>Comma-separated names of the optional files
containing SQL DML statements executed during the
<classname>SessionFactory</classname> creation. This is useful for
testing or demoing: by adding INSERT statements for example you
can populate your database with a minimal set of data when it is
deployed.</para><para>File order matters, the statements of a give
file are executed before the statements of the following files.
These statements are only executed if the schema is created ie if
<literal>hibernate.hbm2ddl.auto</literal> is set to
<literal>create</literal> or
<literal>create-drop</literal>.</para><para> <emphasis
role="strong">e.g.</emphasis>
<literal>/humans.sql,/dogs.sql</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.hbm2ddl.import_files_sql_extractor</literal></entry>
<entry><para>The classname of a custom <interfacename>ImportSqlCommandExtractor</interfacename>
(defaults to the built-in <classname>SingleLineSqlCommandExtractor</classname>).
This is useful for implementing dedicated parser that extracts
single SQL statements from each import file. Hibernate provides
also <classname>MultipleLinesSqlCommandExtractor</classname> which
supports instructions/comments and quoted strings spread over
multiple lines (mandatory semicolon at the end of each statement).
</para><para><emphasis role="strong">e.g.</emphasis>
<literal>classname.of.ImportSqlCommandExtractor</literal></para></entry>
</row>
<row>
<entry><literal>hibernate.bytecode.use_reflection_optimizer</literal></entry>
<entry><para>Enables the use of bytecode manipulation instead of
runtime reflection. This is a System-level property and cannot be
set in <literal>hibernate.cfg.xml</literal>. Reflection can
sometimes be useful when troubleshooting. Hibernate always
requires either CGLIB or javassist even if you turn off the
optimizer.</para><para> <emphasis role="strong">e.g.</emphasis>
<literal>true</literal> | <literal>false</literal> </para></entry>
</row>
<row>
<entry><literal>hibernate.bytecode.provider</literal></entry>
<entry><para>Both javassist or cglib can be used as byte
manipulation engines; the default is
<literal>javassist</literal>.</para><para> <emphasis
role="strong">e.g.</emphasis> <literal>javassist</literal> |
<literal>cglib</literal> </para></entry>
</row>
</tbody>
</tgroup>
</table>
<section xml:id="configuration-optional-dialects" revision="1">
<title>SQL Dialects</title>
<para>Always set the <literal>hibernate.dialect</literal> property to
the correct <literal>org.hibernate.dialect.Dialect</literal> 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.</para>
<table frame="topbot" xml:id="sql-dialects" revision="3">
<title>Hibernate SQL Dialects
(<literal>hibernate.dialect</literal>)</title>
<tgroup cols="2">
<!--
<colspec colwidth="1*"/>
<colspec colwidth="2.5*"/>
-->
<thead>
<row>
<entry>RDBMS</entry>
<entry>Dialect</entry>
</row>
</thead>
<tbody>
<row>
<entry>DB2</entry>
<entry><literal>org.hibernate.dialect.DB2Dialect</literal></entry>
</row>
<row>
<entry>DB2 AS/400</entry>
<entry><literal>org.hibernate.dialect.DB2400Dialect</literal></entry>
</row>
<row>
<entry>DB2 OS390</entry>
<entry><literal>org.hibernate.dialect.DB2390Dialect</literal></entry>
</row>
<row>
<entry>PostgreSQL 8.1</entry>
<entry><literal>org.hibernate.dialect.PostgreSQL81Dialect</literal></entry>
</row>
<row>
<entry>PostgreSQL 8.2 and later</entry>
<entry><literal>org.hibernate.dialect.PostgreSQL82Dialect</literal></entry>
</row>
<row>
<entry>MySQL5</entry>
<entry><literal>org.hibernate.dialect.MySQL5Dialect</literal></entry>
</row>
<row>
<entry>MySQL5 with InnoDB</entry>
<entry><literal>org.hibernate.dialect.MySQL5InnoDBDialect</literal></entry>
</row>
<row>
<entry>MySQL with MyISAM</entry>