Hibernate學(xué)習(xí)之hibernate.cfg.xml配置
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration> <session-factory> <!-- properties --> <!-- 數(shù)據(jù)庫URL --> <property name="hibernate.connection.url">jdbc:mysql://localhost/tablepersubclass</property> <!-- 數(shù)據(jù)庫JDBC驅(qū)動(dòng) --> <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property> <!-- 數(shù)據(jù)庫用戶名 --> <property name="hibernate.connection.username">root</property> <!-- 數(shù)據(jù)庫密碼 --> <property name="hibernate.connection.password">hello</property> <!-- 數(shù)據(jù)庫方言 --> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property> <!-- 是否日志調(diào)試 --> <property name="show_sql">true</property> <!-- 是否使用數(shù)據(jù)庫外連接 --> <property name="use_outer_join">true</property> <!-- 事務(wù)管理 使用JDBC Transaction(使用JTA會(huì)報(bào)錯(cuò)) --> <property name="transaction.factory_class"> net.sf.hibernate.transaction.JDBCTransactionFactory </property> <!-- 映射文件配置,配置文件名必須包含其相對(duì)于根的全路徑 --> <mapping resource="com/model/TItem.hbm.xml" /> </session-factory> </hibernate-configuration>
把日志調(diào)試設(shè)置為true,需要log4j.properties配置文件支持
log4j.properties
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=warn, stdout
log4j.logger.net.sf.hibernate=info
### log just the SQL
#log4j.logger.net.sf.hibernate.SQL=debug
### log JDBC bind parameters 把這一行改為debug ###
log4j.logger.net.sf.hibernate.type=debug
### log schema export/update ###
log4j.logger.net.sf.hibernate.tool.hbm2ddl=debug
### log cache activity ###
#log4j.logger.net.sf.hibernate.cache=debug
### log jdbc resource acquisition
#log4j.logger.net.sf.hibernate.impl.BatcherImpl=debug
### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace
posted on 2011-08-23 09:22 日出星辰 閱讀(92) 評(píng)論(0) 編輯 收藏