Hibernate 配置文件

2021-07-15 08:04

阅读:757

标签:err   tla   键值   自动   小数点   structure   最大的   保留   cluster   

映射文件(.hbm.xml)

技术分享技术分享
 1 xml version="1.0" encoding="UTF-8"?>
 2 DOCTYPE hibernate-mapping PUBLIC 
 3     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 4     "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
 5     
 7  hibernate-mapping package="com.itheima.a_hello" >
 8      
16      class name="User" table="t_user"  >
17          
24         id name="id" column="id" length="255"   >
25             
35             generator class="uuid">generator>
36         id>     
37         
48          
54         property name="name" column="name" update="true" type="string" >property>
55         property name="password" column="password">property>
56          property name="sal" column="sal" precision="2" scale="3" >property>
57      class>
58  hibernate-mapping>
User.hbm.xml

核心配置文件(hibernate.cfg.xml)

技术分享技术分享
 1 xml version="1.0" encoding="UTF-8"?>
 2 DOCTYPE hibernate-configuration PUBLIC
 3     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 4     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
 5 
 6 hibernate-configuration>
 7     session-factory>
 8         
11           
12         property name="hibernate.connection.driver_class">com.mysql.jdbc.Driverproperty>
13           
14         property name="hibernate.connection.username">rootproperty>
15           
16         property name="hibernate.connection.password">1234property>
17           
18         property name="hibernate.connection.url">jdbc:mysql://localhost:3306/EE19Day01property>
19         
20         
21         property name="show_sql">trueproperty>
22         
23         property name="format_sql">trueproperty>
24         
32         property name="hbm2ddl.auto">updateproperty>
33         
34         
37         property name="hibernate.dialect">org.hibernate.dialect.MySQLDialectproperty>
38         
39         
40         
41         
42         property name="hibernate.connection.autocommit">trueproperty>
43         
44         property name="hibernate.current_session_context_class">threadproperty>
45         
48         mapping resource="com/itheima/a_hello/User.hbm.xml"/>
49     session-factory>
50 hibernate-configuration>
hibernate.cfg.xml

 

工具类

技术分享技术分享
 1 package com.ittest.hibernate.utils;
 2 
 3 import org.hibernate.SessionFactory;
 4 import org.hibernate.cfg.Configuration;
 5 
 6 public class Hibernate_session_Utils {
 7 
 8     private Hibernate_session_Utils(){
 9         
10     }
11     private static SessionFactory sf;
12     
13     static{
14         sf =  new Configuration().configure().buildSessionFactory();
15         
16         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
17             
18             @Override
19             public void run() {   //设置程序结束自动关闭该sessionfactory。
20             /*    System.out.println("虚拟机关闭!释放资源");*/
21                 sf.close();
22             }
23         }));
24     }
25     
26     public static org.hibernate.Session openSession(){
27         return sf.openSession();
28     }
29     
30     public static org.hibernate.Session getCurrentSession(){
31         return sf.getCurrentSession();
32     }
33     
34     /*public static void main(String [] args){
35         System.out.println(openSession());
36     }*/
37     
38 }
Hibernate_session_utile.java

 

 

原配置文件(hibernate.properties)

技术分享技术分享
  1 ######################
  2 ### Query Language ###
  3 ######################
  4 
  5 ## define query language constants / function names
  6 
  7 hibernate.query.substitutions yes ‘Y‘, no ‘N‘
  8 
  9 
 10 ## select the classic query parser
 11 
 12 #hibernate.query.factory_class org.hibernate.hql.classic.ClassicQueryTranslatorFactory
 13 
 14 
 15 
 16 #################
 17 ### Platforms ###
 18 #################
 19 
 20 ## JNDI Datasource
 21 
 22 #hibernate.connection.datasource jdbc/test
 23 #hibernate.connection.username db2
 24 #hibernate.connection.password db2
 25 
 26 
 27 ## HypersonicSQL
 28 
 29 hibernate.dialect org.hibernate.dialect.HSQLDialect
 30 hibernate.connection.driver_class org.hsqldb.jdbcDriver
 31 hibernate.connection.username sa
 32 hibernate.connection.password
 33 hibernate.connection.url jdbc:hsqldb:./build/db/hsqldb/hibernate
 34 #hibernate.connection.url jdbc:hsqldb:hsql://localhost
 35 #hibernate.connection.url jdbc:hsqldb:test
 36 
 37 ## H2 (www.h2database.com)
 38 #hibernate.dialect org.hibernate.dialect.H2Dialect
 39 #hibernate.connection.driver_class org.h2.Driver
 40 #hibernate.connection.username sa
 41 #hibernate.connection.password
 42 #hibernate.connection.url jdbc:h2:mem:./build/db/h2/hibernate
 43 #hibernate.connection.url jdbc:h2:testdb/h2test
 44 #hibernate.connection.url jdbc:h2:mem:imdb1
 45 #hibernate.connection.url jdbc:h2:tcp://dbserv:8084/sample;     
 46 #hibernate.connection.url jdbc:h2:ssl://secureserv:8085/sample;     
 47 #hibernate.connection.url jdbc:h2:ssl://secureserv/testdb;cipher=AES
 48 
 49 ## MySQL
 50 
 51 #hibernate.dialect org.hibernate.dialect.MySQLDialect
 52 #hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
 53 #hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
 54 #hibernate.connection.driver_class com.mysql.jdbc.Driver
 55 #hibernate.connection.url jdbc:mysql:///test
 56 #hibernate.connection.username gavin
 57 #hibernate.connection.password
 58 
 59 
 60 ## Oracle
 61 
 62 #hibernate.dialect org.hibernate.dialect.Oracle8iDialect
 63 #hibernate.dialect org.hibernate.dialect.Oracle9iDialect
 64 #hibernate.dialect org.hibernate.dialect.Oracle10gDialect
 65 #hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
 66 #hibernate.connection.username ora
 67 #hibernate.connection.password ora
 68 #hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl
 69 #hibernate.connection.url jdbc:oracle:thin:@localhost:1522:XE
 70 
 71 
 72 ## PostgreSQL
 73 
 74 #hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
 75 #hibernate.connection.driver_class org.postgresql.Driver
 76 #hibernate.connection.url jdbc:postgresql:template1
 77 #hibernate.connection.username pg
 78 #hibernate.connection.password
 79 
 80 
 81 ## DB2
 82 
 83 #hibernate.dialect org.hibernate.dialect.DB2Dialect
 84 #hibernate.connection.driver_class com.ibm.db2.jcc.DB2Driver
 85 #hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
 86 #hibernate.connection.url jdbc:db2://localhost:50000/somename
 87 #hibernate.connection.url jdbc:db2:somename
 88 #hibernate.connection.username db2
 89 #hibernate.connection.password db2
 90 
 91 ## TimesTen
 92 
 93 #hibernate.dialect org.hibernate.dialect.TimesTenDialect
 94 #hibernate.connection.driver_class com.timesten.jdbc.TimesTenDriver
 95 #hibernate.connection.url jdbc:timesten:direct:test
 96 #hibernate.connection.username
 97 #hibernate.connection.password 
 98 
 99 ## DB2/400
100 
101 #hibernate.dialect org.hibernate.dialect.DB2400Dialect
102 #hibernate.connection.username user
103 #hibernate.connection.password password
104 
105 ## Native driver
106 #hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
107 #hibernate.connection.url jdbc:db2://systemname
108 
109 ## Toolbox driver
110 #hibernate.connection.driver_class com.ibm.as400.access.AS400JDBCDriver
111 #hibernate.connection.url jdbc:as400://systemname
112 
113 
114 ## Derby (not supported!)
115 
116 #hibernate.dialect org.hibernate.dialect.DerbyDialect
117 #hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver
118 #hibernate.connection.username
119 #hibernate.connection.password
120 #hibernate.connection.url jdbc:derby:build/db/derby/hibernate;create=true
121 
122 
123 ## Sybase
124 
125 #hibernate.dialect org.hibernate.dialect.SybaseDialect
126 #hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver
127 #hibernate.connection.username sa
128 #hibernate.connection.password sasasa
129 #hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb
130 
131 
132 ## Mckoi SQL
133 
134 #hibernate.dialect org.hibernate.dialect.MckoiDialect
135 #hibernate.connection.driver_class com.mckoi.JDBCDriver
136 #hibernate.connection.url jdbc:mckoi:///
137 #hibernate.connection.url jdbc:mckoi:local://C:/mckoi1.0.3/db.conf
138 #hibernate.connection.username admin
139 #hibernate.connection.password nimda
140 
141 
142 ## SAP DB
143 
144 #hibernate.dialect org.hibernate.dialect.SAPDBDialect
145 #hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
146 #hibernate.connection.url jdbc:sapdb://localhost/TST
147 #hibernate.connection.username TEST
148 #hibernate.connection.password TEST
149 #hibernate.query.substitutions yes ‘Y‘, no ‘N‘
150 
151 
152 ## MS SQL Server
153 
154 #hibernate.dialect org.hibernate.dialect.SQLServerDialect
155 #hibernate.connection.username sa
156 #hibernate.connection.password sa
157 
158 ## JSQL Driver
159 #hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver
160 #hibernate.connection.url jdbc:JSQLConnect://1E1/test
161 
162 ## JTURBO Driver
163 #hibernate.connection.driver_class com.newatlanta.jturbo.driver.Driver
164 #hibernate.connection.url jdbc:JTurbo://1E1:1433/test
165 
166 ## WebLogic Driver
167 #hibernate.connection.driver_class weblogic.jdbc.mssqlserver4.Driver
168 #hibernate.connection.url jdbc:weblogic:mssqlserver4:1E1:1433
169 
170 ## Microsoft Driver (not recommended!)
171 #hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
172 #hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor
173 
174 ## The New Microsoft Driver 
175 #hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
176 #hibernate.connection.url jdbc:sqlserver://localhost
177 
178 ## jTDS (since version 0.9)
179 #hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
180 #hibernate.connection.url jdbc:jtds:sqlserver://1E1/test
181 
182 ## Interbase
183 
184 #hibernate.dialect org.hibernate.dialect.InterbaseDialect
185 #hibernate.connection.username sysdba
186 #hibernate.connection.password masterkey
187 
188 ## DO NOT specify hibernate.connection.sqlDialect
189 
190 ## InterClient
191 
192 #hibernate.connection.driver_class interbase.interclient.Driver
193 #hibernate.connection.url jdbc:interbase://localhost:3060/C:/firebird/test.gdb
194 
195 ## Pure Java
196 
197 #hibernate.connection.driver_class org.firebirdsql.jdbc.FBDriver
198 #hibernate.connection.url jdbc:firebirdsql:localhost/3050:/firebird/test.gdb
199 
200 
201 ## Pointbase
202 
203 #hibernate.dialect org.hibernate.dialect.PointbaseDialect
204 #hibernate.connection.driver_class com.pointbase.jdbc.jdbcUniversalDriver
205 #hibernate.connection.url jdbc:pointbase:embedded:sample
206 #hibernate.connection.username PBPUBLIC
207 #hibernate.connection.password PBPUBLIC
208 
209 
210 ## Ingres
211 
212 ## older versions (before Ingress 2006)
213 
214 #hibernate.dialect org.hibernate.dialect.IngresDialect
215 #hibernate.connection.driver_class ca.edbc.jdbc.EdbcDriver
216 #hibernate.connection.url jdbc:edbc://localhost:II7/database
217 #hibernate.connection.username user
218 #hibernate.connection.password password
219 
220 ## Ingres 2006 or later
221 
222 #hibernate.dialect org.hibernate.dialect.IngresDialect
223 #hibernate.connection.driver_class com.ingres.jdbc.IngresDriver
224 #hibernate.connection.url jdbc:ingres://localhost:II7/database;CURSOR=READONLY;auto=multi
225 #hibernate.connection.username user
226 #hibernate.connection.password password
227 
228 ## Mimer SQL
229 
230 #hibernate.dialect org.hibernate.dialect.MimerSQLDialect
231 #hibernate.connection.driver_class com.mimer.jdbc.Driver
232 #hibernate.connection.url jdbc:mimer:multi1
233 #hibernate.connection.username hibernate
234 #hibernate.connection.password hibernate
235 
236 
237 ## InterSystems Cache
238 
239 #hibernate.dialect org.hibernate.dialect.Cache71Dialect
240 #hibernate.connection.driver_class com.intersys.jdbc.CacheDriver
241 #hibernate.connection.username _SYSTEM
242 #hibernate.connection.password SYS
243 #hibernate.connection.url jdbc:Cache://127.0.0.1:1972/HIBERNATE
244 
245 
246 #################################
247 ### Hibernate Connection Pool ###
248 #################################
249 
250 hibernate.connection.pool_size 1
251 
252 
253 
254 ###########################
255 ### C3P0 Connection Pool###
256 ###########################
257 
258 #hibernate.c3p0.max_size 2
259 #hibernate.c3p0.min_size 2
260 #hibernate.c3p0.timeout 5000
261 #hibernate.c3p0.max_statements 100
262 #hibernate.c3p0.idle_test_period 3000
263 #hibernate.c3p0.acquire_increment 2
264 #hibernate.c3p0.validate false
265 
266 
267 
268 ##############################
269 ### Proxool Connection Pool###
270 ##############################
271 
272 ## Properties for external configuration of Proxool
273 
274 hibernate.proxool.pool_alias pool1
275 
276 ## Only need one of the following
277 
278 #hibernate.proxool.existing_pool true
279 #hibernate.proxool.xml proxool.xml
280 #hibernate.proxool.properties proxool.properties
281 
282 
283 
284 #################################
285 ### Plugin ConnectionProvider ###
286 #################################
287 
288 ## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)
289 
290 #hibernate.connection.provider_class org.hibernate.connection.DriverManagerConnectionProvider
291 #hibernate.connection.provider_class org.hibernate.connection.DatasourceConnectionProvider
292 #hibernate.connection.provider_class org.hibernate.connection.C3P0ConnectionProvider
293 #hibernate.connection.provider_class org.hibernate.connection.ProxoolConnectionProvider
294 
295 
296 
297 #######################
298 ### Transaction API ###
299 #######################
300 
301 ## Enable automatic flush during the JTA beforeCompletion() callback
302 ## (This setting is relevant with or without the Transaction API)
303 
304 #hibernate.transaction.flush_before_completion
305 
306 
307 ## Enable automatic session close at the end of transaction
308 ## (This setting is relevant with or without the Transaction API)
309 
310 #hibernate.transaction.auto_close_session
311 
312 
313 ## the Transaction API abstracts application code from the underlying JTA or JDBC transactions
314 
315 #hibernate.transaction.factory_class org.hibernate.transaction.JTATransactionFactory
316 #hibernate.transaction.factory_class org.hibernate.transaction.JDBCTransactionFactory
317 
318 
319 ## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
320 ## default is java:comp/UserTransaction
321 ## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class
322 
323 #jta.UserTransaction jta/usertransaction
324 #jta.UserTransaction javax.transaction.UserTransaction
325 #jta.UserTransaction UserTransaction
326 
327 
328 ## to use the second-level cache with JTA, Hibernate must be able to obtain the JTA TransactionManager
329 
330 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.JBossTransactionManagerLookup
331 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.WeblogicTransactionManagerLookup
332 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.WebSphereTransactionManagerLookup
333 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.OrionTransactionManagerLookup
334 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.ResinTransactionManagerLookup
335 
336 
337 
338 ##############################
339 ### Miscellaneous Settings ###
340 ##############################
341 
342 ## print all generated SQL to the console
343 
344 #hibernate.show_sql true
345 
346 
347 ## format SQL in log and console
348 
349 hibernate.format_sql true
350 
351 
352 ## add comments to the generated SQL
353 
354 #hibernate.use_sql_comments true
355 
356 
357 ## generate statistics
358 
359 #hibernate.generate_statistics true
360 
361 
362 ## auto schema export
363 
364 #hibernate.hbm2ddl.auto create-drop
365 #hibernate.hbm2ddl.auto create
366 #hibernate.hbm2ddl.auto update
367 #hibernate.hbm2ddl.auto validate
368 
369 
370 ## specify a default schema and catalog for unqualified tablenames
371 
372 #hibernate.default_schema test
373 #hibernate.default_catalog test
374 
375 
376 ## enable ordering of SQL UPDATEs by primary key
377 
378 #hibernate.order_updates true
379 
380 
381 ## set the maximum depth of the outer join fetch tree
382 
383 hibernate.max_fetch_depth 1
384 
385 
386 ## set the default batch size for batch fetching
387 
388 #hibernate.default_batch_fetch_size 8
389 
390 
391 ## rollback generated identifier values of deleted entities to default values
392 
393 #hibernate.use_identifer_rollback true
394 
395 
396 ## enable bytecode reflection optimizer (disabled by default)
397 
398 #hibernate.bytecode.use_reflection_optimizer true
399 
400 
401 
402 #####################
403 ### JDBC Settings ###
404 #####################
405 
406 ## specify a JDBC isolation level
407 
408 #hibernate.connection.isolation 4
409 
410 
411 ## enable JDBC autocommit (not recommended!)
412 
413 #hibernate.connection.autocommit true
414 
415 
416 ## set the JDBC fetch size
417 
418 #hibernate.jdbc.fetch_size 25
419 
420 
421 ## set the maximum JDBC 2 batch size (a nonzero value enables batching)
422 
423 #hibernate.jdbc.batch_size 5
424 #hibernate.jdbc.batch_size 0
425 
426 
427 ## enable batch updates even for versioned data
428 
429 hibernate.jdbc.batch_versioned_data true
430 
431 
432 ## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)
433 
434 #hibernate.jdbc.use_scrollable_resultset true
435 
436 
437 ## use streams when writing binary types to / from JDBC
438 
439 hibernate.jdbc.use_streams_for_binary true
440 
441 
442 ## use JDBC 3 PreparedStatement.getGeneratedKeys() to get the identifier of an inserted row
443 
444 #hibernate.jdbc.use_get_generated_keys false
445 
446 
447 ## choose a custom JDBC batcher
448 
449 # hibernate.jdbc.factory_class
450 
451 
452 ## enable JDBC result set column alias caching 
453 ## (minor performance enhancement for broken JDBC drivers)
454 
455 # hibernate.jdbc.wrap_result_sets
456 
457 
458 ## choose a custom SQL exception converter
459 
460 #hibernate.jdbc.sql_exception_converter
461 
462 
463 
464 ##########################
465 ### Second-level Cache ###
466 ##########################
467 
468 ## optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache)
469 
470 #hibernate.cache.use_minimal_puts true
471 
472 
473 ## set a prefix for cache region names
474 
475 hibernate.cache.region_prefix hibernate.test
476 
477 
478 ## disable the second-level cache
479 
480 #hibernate.cache.use_second_level_cache false
481 
482 
483 ## enable the query cache
484 
485 #hibernate.cache.use_query_cache true
486 
487 
488 ## store the second-level cache entries in a more human-friendly format
489 
490 #hibernate.cache.use_structured_entries true
491 
492 
493 ## choose a cache implementation
494 
495 #hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider
496 #hibernate.cache.provider_class org.hibernate.cache.EmptyCacheProvider
497 hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
498 #hibernate.cache.provider_class org.hibernate.cache.TreeCacheProvider
499 #hibernate.cache.provider_class org.hibernate.cache.OSCacheProvider
500 #hibernate.cache.provider_class org.hibernate.cache.SwarmCacheProvider
501 
502 
503 ## choose a custom query cache implementation
504 
505 #hibernate.cache.query_cache_factory
506 
507 
508 
509 ############
510 ### JNDI ###
511 ############
512 
513 ## specify a JNDI name for the SessionFactory
514 
515 #hibernate.session_factory_name hibernate/session_factory
516 
517 
518 ## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
519 ## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
520 ## is the best approach in an application server
521 
522 #file system
523 #hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
524 #hibernate.jndi.url file:/
525 
526 #WebSphere
527 #hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
528 #hibernate.jndi.url iiop://localhost:900/
hibernate.properties

 

Hibernate 配置文件

标签:err   tla   键值   自动   小数点   structure   最大的   保留   cluster   

原文地址:http://www.cnblogs.com/soficircle/p/7073914.html


评论


亲,登录后才可以留言!