-
Hibernate
添加时间:2013-7-9 点击量:Hibernate的景象搭建
一、项目相干的jar包12个:
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
ejb3-persistence.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
log4j-1.2.15.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
还要参加数据库的相干的JDBC驱动的jar包:mysql-connector-java-5.1.25-bin.jar(MySQL),ojdbc14.jar(Oracle)。
可以到http://www.docjar.com/网站。
二、设备核心文件hibernate .cfg.xml
<?xml version=1.0 encoding=utf-8?>
<!DOCTYPE hibernate-configuration PUBLIC
-//Hibernate/Hibernate Configuration DTD 3.0//EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<!--mysql settings
<property name=connection.driver_class>com.mysql.jdbc.Driver</property>
<property name=connection.url>jdbc:mysql://localhost/hibernate</property>
<property name=connection.username>root</property>
<property name=connection.password>196691</property>
-->
<property name=connection.driver_class>oracle.jdbc.driver.OracleDriver</property>
<property name=connection.url>jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name=connection.username>root</property>
<property name=connection.password>root</property>
<!-- JDBC connection pool (use the built-in) -->
<!-- <property name=connection.pool_size>1</property> -->
<!-- SQL dialect -->
<property name=dialect>org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernates automatic session context management -->
<!-- <property name=current_session_context_class>thread</property> -->
<!-- Disable the second-level cache -->
<property name=cache.provider_class>org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name=show_sql>true</property>
<!-- Drop and re-create the database schema on startup -->
<property name=hbm2ddl.auto>create</property>
<mapping resource=com/qs/hibernate/model/Student.hbm.xml />
<mapping class=com.qs.hibernate.model.Teacher />
</session-factory>
</hibernate-configuration>
三、参加log4j设备文件log4j.properties,将该设备文件拷贝到src下,便于法度调试。
### 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.org.hibernate=info
#log4j.logger.org.hibernate=debug
### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug
### log just the SQL
#log4j.logger.org.hibernate.SQL=debug
### log JDBC bind parameters ###
#log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug
### log schema export/ ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug
### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug
### log cache activity ###
#log4j.logger.org.hibernate.cache=debug
### log transaction activity
#log4j.logger.org.hibernate.transaction=debug
### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug
### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace