zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Hibernate配置属性

2023-06-13 09:12:00 时间
Hibernate 通过读取默认的配置文件来加载数据库配置信息,该配置文件应放于 classpath 根目录下,默认的配置文件名称为 Hibernate.cfg.xml。Hibernate.cfg.xml 文件中不仅包含数据库的配置信息,而且包含了用户对 Hibernate 所设置的属性信息,如打印 SQL 语句、自动建表等。其配置方法如下:


 ?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 

 !--数据库驱动-- 

 property name= connection.driver_class com.mysql.jdbc.Driver /property 

 !--数据库连接的URL-- 

 property name= connection.url jdbc:mysql://localhost:3306/test /property 

 !--数据库连接用户名-- 

 property name= connection.username root /property 

 !--数据库连接密码-- 

 property name= connection.password 111 /property 

 !--Hibernate方言-- 

 property name= dialect org.hibernate.dialect.MySQLDialect /property 

 !--打印SQL语句-- 

 property name= show_sql true /property 

 !--映射文件-- 

 mapping resource= com/lyq/User.hbm.xml / 

 /session-factory 

 /hibernate-configuration 

22944.html

Hibernatejavamysql