persistence.xml
15.4 KB
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
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
>
<persistence-unit name="${pu.name}" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>${pu.jta.data.source}</jta-data-source>
<!-- <non-jta-data-source>${pu.jta.data.source}Unmanaged</non-jta-data-source> -->
<properties>
<property name="hibernate.dialect" value="${pu.hibernate.dialect}" />
<property name="hibernate.hbm2ddl.auto" value="${pu.hibernate.hbm2ddl.auto}" />
<property name="hibernate.default_batch_fetch_size" value="${pu.hibernate.default_batch_fetch_size}" />
<property name="hibernate.show_sql" value="${pu.hibernate.show_sql}" />
<property name="hibernate.format_sql" value="true" />
<!-- Encoding -->
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<!-- These are the default for JBoss EJB3, but not for HEM: -->
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.transaction.manager_lookup_class" value="${pu.hibernate.transaction.manager_lookup_class}" />
<!--
Binds the EntityManagerFactory to JNDI where Seam can look it up.
This is only relevant when the container automatically loads the persistence unit,
as is the case in JBoss AS 5.
-->
<property name="jboss.entity.manager.factory.jndi.name" value="${pu.jboss.entity.manager.factory.jndi.name}" />
</properties>
<!--
If the persistence.xml file is not under the same root directory or jar than your domain
model then use the <jar-file> element to point to the jar containing your domain model.
<jar-file>../../vehicles.jar</jar-file>
-->
</persistence-unit>
</persistence>
<!--
The persistence.xml file configures the back-end database source for the EntityManager and is the
standard deployment descriptor used to configure a JPA persistence context.
see: http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/configuration.html
see: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html
persistence-unit :
name : Every entity manager must have a name.
transaction-type : Transaction type used. Either JTA or RESOURCE_LOCAL (default to JTA in a
JavaEE environment and to RESOURCE_LOCAL in a JavaSE environment).
When a jta-datasource is used, the default is JTA, if non-jta-datasource is
used, RESOURCE_LOCAL is used.
provider : The provider only needs to be set if you use several JPA providers, eg.
org.hibernate.ejb.HibernatePersistence
jta-data-source,
non-jta-data-source : This is the JNDI name of where the javax.sql.DataSource is located. When
running without a JNDI available Datasource, you must specify JDBC
connections with Hibernate specific properties (see below).
mapping-file : The class element specifies a EJB3 compliant XML mapping file that you will
map. The file has to be in the classpath. As per the EJB3 specification,
Hibernate EntityManager will try to load the mapping file located in the jar
file at META_INF/orm.xml. Of course any explicit mapping file will be loaded
too. As a matter of fact, you can provides any XML file in the mapping file
element ie. either hbm files or EJB3 deployment descriptor.
jar-file : The jar-file elements specifies a jar to analyse. All properly annotated
classes, annotated packages and all hbm.xml files part of this jar file will
be added to the persistence unit configuration. This element is mainly used
in Java EE environment. Use of this one in Java SE should be considered as
non portable, in this case a absolute url is needed. You can alternatively
point to a directory (This is especially useful when in your test
environment, the persistence.xml file is not under the same root directory
or jar than your domain model).
<jar-file>file:/home/turin/work/local/lab8/build/classes</jar-file>
exclude-unlisted-
classes : Do not check the main jar file for annotated classes. Only explicit classes
will be part of the persistence unit.
class : The class element specifies a fully qualified class name that you will map.
By default all properly annotated classes and all hbm.xml files found inside
the archive are added to the persistence unit configuration. You can add
some external entity through the class element though. As an extension to
the specification, you can add a package name in the <class> element
(eg <class>org.hibernate.eg</class>). Caution, the package will include the
metadata defined at the package level (ie in package-info.java), it will not
include all the classes of a given package. This is required to be spec
compliant, Hibernate however supports auto-detection even in JSE.
properties : The properties element is used to specify vendor specific properties. This
is where you will define your Hibernate specific configurations. This is
also where you will have to specify JDBC connection information as well.
see: http://www.hibernate.org/hib_docs/reference/en/html/configuration-optional.html
Hibernate Configuration Properties:
see: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html
===================================
hibernate-dialect : The classname of a Hibernate org.hibernate.dialect.Dialect which
allows Hibernate to generate SQL optimized for a particular relational
database. You should always set the hibernate.dialect property to the
correct org.hibernate.dialect.Dialect subclass for your database. If
you specify a dialect, Hibernate will use sensible defaults for some
of the other properties listed here, saving you the effort of
specifying them manually.
For MySql use one of the following:
MySQL org.hibernate.dialect.MySQLDialect
MySQL5 org.hibernate.dialect.MySQL5Dialect
MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect
hibernate.show_sql : Write all SQL statements to console. This is an alternative to setting
the log category org.hibernate.SQL to debug. eg. true | false
hibernate.format_sql : Pretty print the SQL in the log and console. eg. true | false
hibernate.default_schema: Qualify unqualified table names with the given schema/tablespace in
generated SQL. eg. SCHEMA_NAME
hibernate.
default_catalog : Qualify unqualified table names with the given catalog in generated
SQL. eg. CATALOG_NAME
hibernate.
session_factory_name : The org.hibernate.SessionFactory will be automatically bound to this
name in JNDI after it has been created.
e.g. jndi/composite/name
hibernate.
generate_statistics : If enabled, Hibernate will collect statistics useful for performance
tuning. eg. true | false
hibernate.
use_sql_comments : If turned on, Hibernate will generate comments inside the SQL, for
easier debugging, defaults to false. eg. true | false
hibernate.archive.
autodetection : Scan for annotated classes and Hibernate mapping XML files,
eg. class, hbm
Hibernate JDBC and Connection Properties:
=========================================
hibernate.
default_batch_fetch_size: Sets a default size for Hibernate batch fetching of associations.
e.g. recommended values 4, 8, 16 (SiA-p417).
hibernate.jdbc.charSet : e.g. utf-8
hibernate.jdbc.
fetch_size : A non-zero value determines the JDBC fetch size
(calls Statement.setFetchSize()).
hibernate.jdbc.
batch_size : A non-zero value enables use of JDBC2 batch updates by Hibernate.
eg. recommended values between 5 and 30
hibernate.jdbc.
batch_versioned_data : Set this property to true if your JDBC driver returns correct row
counts from executeBatch() (it is usually safe to turn this option on).
Hibernate will then use batched DML for automatically versioned data.
Defaults to false. eg. true | false
Hibernate Cache Properties:
===========================
The properties prefixed by hibernate.cache allow you to use a process or cluster scoped
second-level cache system with Hibernate. see:
http://www.hibernate.org/hib_docs/reference/en/html/performance-cache.html for more details.
hibernate.cache.
provider_class : The classname of a custom CacheProvider. Default for JBoss EJB3 is:
org.hibernate.cache.HashtableCacheProvider
The property needs to be set for running outside of JBoss for testing
hibernate.cache.
use_minimal_puts : Optimize 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. eg. true|false
hibernate.cache.
use_query_cache : Enable the query cache, individual queries still have to be set
cachable. eg. true|false
hibernate.cache.
use_second_level_cache : May be used to completely disable the second level cache, which is
enabled by default for classes which specify a <cache> mapping.
eg. true|false
hibernate.cache.
query_cache_factory : The classname of a custom QueryCache interface, defaults to the
built-in StandardQueryCache. eg. classname.of.QueryCache
hibernate.cache.
region_prefix : A prefix to use for second-level cache region names. eg. prefix
hibernate.cache.
use_structured_entries : Forces Hibernate to store data in the second-level cache in a more
human-friendly format. eg. true|false
hibernate.cache.
provider_configuration :
Hibernate Transaction Properties:
=================================
hibernate.transaction.
factory_class : The classname of a TransactionFactory to use with Hibernate
Transaction API (defaults to JDBCTransactionFactory).
eg. classname.of.TransactionFactory
hibernate.transaction.
manager_lookup_class : The classname of a TransactionManagerLookup - required when JVM-level
caching is enabled or when using hilo generator in a JTA environment.
eg. classname.of.TransactionManagerLookup. Default for JBoss EJB3 is:
org.hibernate.transaction.JBossTransactionManagerLookup
The property needs to be set for running outside of JBoss for testing
hibernate.transaction.
flush_before_completion : 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:
http://www.hibernate.org/hib_docs/reference/en/html/architecture-current-session.html
hibernate.transaction.
auto_close_session : If enabled, the session will be automatically closed during the after
completion phase of the transaction. Built-in and utomatic session
context management is preferred, see:
http://www.hibernate.org/hib_docs/reference/en/html/architecture-current-session.html
Hibernate Search:
=================
@TODO: Document Hibernate Search properties here
Miscellaneous Properties:
=========================
hibernate.
hbm2ddl.auto : Automatically validate or export schema DDL to the database when the
SessionFactory is created. With create-drop, the database schema will be
dropped when the SessionFactory is closed explicitly.
eg. validate | update | create | create-drop
hibernate.ejb.cfgfile : alternatively to <class> and <property> declarations, you can use a
regular hibernate.cfg.xml file, eg.
<property name="hibernate.ejb.cfgfile"
value="/org/hibernate/ejb/test/hibernate.cfg.xml"/>
JBoss Configuration Properties:
===============================
jboss.entity.manager.
factory.jndi.name : Binds the EntityManagerFactory to JNDI where Seam can look it up.
This is only relevant when the container automatically loads the
persistence unit, as is the case in JBoss AS 5.
Put the EntityManagerFactory into JNDI so we can use it manually in
tests, eg. java:/jpaBookingEntityManagerFactory.
(This is an alternative to using the property
hibernate.transaction.manager_lookup_class )
-->