Configuration 类
Configuration 类负责管理 Hibernate 的配置信息。Hibernate 运行时需要
MyEclipse 6 Java开发中文教程
102 刘长炯著
获取一些底层实现的基本信息,其中几个关键属性包括:
数据库URL
数据库用户
数据库用户密码
数据库JDBC 驱动类
数据库dialect ,用于对特定数据库提供支持,其中包含了针对特定数据库特性
的实现,如Hibernate数据类型到特定数据库数据类型的映射等。
使用 Hibernate 必须首先提供这些基础信息以完成初始化工作,为后继操作做好准
备。这些属性在 hibernate配置文件(hibernate.cfg.xml )中加以设 定.
调用:
Configuration config = new C onfiguration().configure();
时,Hibernate会自动在当前的 CLASSPATH 中搜寻 hibernate.cfg.xml文件并将其读
取到内存中作为后继操作的基础配置。Configuration 类一般只有在获取 SessionFactory
时需要涉及,当获取 SessionFactory 之后,由于配置信息已经由 Hibernate 维护并绑定
在返回的SessionFactory 之上,因此一般情况下无需再对其进行操作。
示例的配置文件:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-conf iguration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 显示后台的 SQL, 便于调试 -->
<property name="show_sql">true</property>
<property name="connection.username">classiccars</property>
<property name="connection.url">
jdbc:derby://localhost:1527/myeclipse;create=true
</property>
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>
<property
name="connection.driver_class">org.apac he.derby.jdbc.ClientDriver</property>
<property name="connection.password">myeclipse</property>
<!-- 实体映射文件 -->
<mapping resource="dao/User.hbm.xml" />
</session-factory>
Configuration 类负责管理 Hibernate 的配置信息。Hibernate 运行时需要
MyEclipse 6 Java开发中文教程
102 刘长炯著
获取一些底层实现的基本信息,其中几个关键属性包括:
数据库URL
数据库用户
数据库用户密码
数据库JDBC 驱动类
数据库dialect ,用于对特定数据库提供支持,其中包含了针对特定数据库特性
的实现,如Hibernate数据类型到特定数据库数据类型的映射等。
使用 Hibernate 必须首先提供这些基础信息以完成初始化工作,为后继操作做好准
备。这些属性在 hibernate配置文件(hibernate.cfg.xml )中加以设 定.
调用:
Configuration config = new C onfiguration().configure();
时,Hibernate会自动在当前的 CLASSPATH 中搜寻 hibernate.cfg.xml文件并将其读
取到内存中作为后继操作的基础配置。Configuration 类一般只有在获取 SessionFactory
时需要涉及,当获取 SessionFactory 之后,由于配置信息已经由 Hibernate 维护并绑定
在返回的SessionFactory 之上,因此一般情况下无需再对其进行操作。
示例的配置文件:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-conf iguration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 显示后台的 SQL, 便于调试 -->
<property name="show_sql">true</property>
<property name="connection.username">classiccars</property>
<property name="connection.url">
jdbc:derby://localhost:1527/myeclipse;create=true
</property>
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>
<property
name="connection.driver_class">org.apac he.derby.jdbc.ClientDriver</property>
<property name="connection.password">myeclipse</property>
<!-- 实体映射文件 -->
<mapping resource="dao/User.hbm.xml" />
</session-factory>