一、常用配置:
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
>
<!-- 以下属性根据所要连接的数据库进行配置 -->
<
property
name
=
"myeclipse.connection.profile"
>
com.mysql.jdbc.MySqlDriver
</
property
>
<
property
name
=
"hibernate.connection.username"
>
root
</
property
>
<
property
name
=
"hibernate.connection.password"
>
root
</
property
>
<
property
name
=
"hibernate.connection.url"
>
jdbc:mysql://localhost:3306/spring_demo?useUnicode=true
&
characterEncoding=utf-8
</
property
>
<
property
name
=
"hibernate.connection.driver_class"
>
com.mysql.jdbc.Driver
</
property
>
<
property
name
=
"hibernate.dialect"
>
org.hibernate.dialect.MySQLDialect
</
property
>
<
property
name
=
"hibernate.show_sql"
>
true
</
property
>
<
property
name
=
"hibernate.hbm2ddl.auto"
>
validate
</
property
>
<
property
name
=
"dialect"
>
org.hibernate.dialect.MySQLDialect
</
property
>
<!-- 在下面添加实体关系映射文件 -->
<
mapping
resource
=
"com/demo/spring/entity/User.hbm.xml"
/>
</
session-factory
>
</
hibernate-configuration
>