1、hibernate.cfg.xml配置如下:
(数据库连接配置)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE
hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration
DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect
</property>
<property
name="show_sql">true</property>
<property
name="connection.useUnicode">true</property>
<property
name="connection.characterEncoding">UTF-8</property>
<property
name="hbm2ddl.auto">update</property>
<mapping
class="com.entity.ClassRoom"/>
<mapping
class="com.entity.Student"/>
<mapping
class="com.entity.Course"/>
<!--
<mapping
resource="student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
2、xxx.hbm.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE
hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<hibernate-mapping package="com.entity">
<class
name="Student" table="student">
<id
name="stu_id">
<generator class="native"
/>
</id>
<property
name="stu_name"></property>
<property
name="sex"></property>
<property
name="age"></property>
<many-to-one name="clr" cascade="all"
column="clr_id" lazy="false" class="ClassRoom">
</many-to-one>
<!-- <list name="course_list" table="course">
<key
column="stu_id" not-null="true"></key>
<list-index
column="list-order"></list-index>
<element type="string"
column="course_name"></element>
</list>
-->
</class>
</hibernate-mapping>
3、另注一些说明:
hibernate 官网下载 hibernate-search-4.4.2.Final-dist.zip,解压后的文件夹 hibernate-search-4.4.2.Final-dist
以上的jar包来自
hibernate-search-4.4.2.Final-dist\hibernate-search-4.4.2.Final\dist\lib\required中所有jar包
另外又新增了以下几个jar:
<1.hibernate-jpa-2.0-api-1.0.1.Final.jar 这个是用于注解的主要jar包
<2.jta.jar 缺少该jar包启动时出现 java.lang.NoClassDefFoundError :javax.transaction.SystemException异常
以上的两个jar包来自(hibernate-search-4.4.2.Final-dist\hibernate-search-4.4.2.Final\dist\lib\provided)
<3.连接数据库的驱动包.