hibernate_log&配置文件详解
ibernate_log&配置文件详解
1、 log
确定要使用日志的实现——log4j
编写log4j.propertiesa
2、 hibernate.cfg.xml讲解
<hibernate-configuration> <session-factory> <!-- 配置数据库连接信息 --> <!-- 数据库驱动 --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <!-- hibernate可选项信息 --> <!-- 数据库方言 --><!-- hibernate4以上可以直接使用MySQL5Dialect --> <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property> <!-- 是否打印sql语句 --> <property name="show_sql">true</property> <!-- 格式化sql语句 --> <property name="format_sql">true</property> <!-- 数据库更新方式 create:每次执行都先把原有数据表删除,然后创建该表 create-drop:关闭SessionFactory时,将删除掉数据库表 validate:检测 update:如果表不存在则直接创建表,有就不用创建 --> <property name="hbm2ddl.auto">update</property> <!-- 映射文件信息 --> <mapping resource="com/yxxy/pojo/User.hbm.xml"/> </session-factory> </hibernate-configuration> |