Hibernate的配置文件 Hibernate.cfg.xml与xxx.hbm.xml
2014-05-09 16:18
525 查看
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.连接数据库的驱动包.
(数据库连接配置)
<?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.连接数据库的驱动包.
相关文章推荐
- 使用hibernate连接mysql数据库正向工程hibernate.cfg.xml文件和xxx.hbm.xml配置文件
- hibernate映射配置文件(xxx.hbm.xml)内容及作用
- Hibernate.cfg.xml注解和*.hbm.xml配置文件
- 根据hibernate.cfg.xml配置文件和相应实体类及其.hbm.xml文件生成对应的数据库表
- Hibernate框架中hibernate.properties属性文件,hibernate.cfg.xml配置文件,以及Users.hbm.xml映射文件的配置
- hibernate.cfg.xml配置文件和hbm.xml配置文件 模板
- 用xxx.hbm.xml映射文件配置的hibernate实例
- Hibernate学习-08:配置-核心配置文件hibernate.cfg.xml、映射文件*.hbm.xml
- Hibernate3.5.4---java application的xml和annotation环境搭建(hibernate.cfg.xml配置文件说明,映射文件Student.hbm.xml说明
- maven hibernate hibernate.cfg.xml以及 XXX.hbm.xml文件找不到
- 使用Xdoclet生成Hibernate配置文件(hibernate.cfg.xml)和Hibernate映射文件(*.hbm.xml)
- hibernate映射文件XXX.hbm.xml配置映射元素详解--对象标识符(OID)
- hibernate中写配置文件xxx.hbm.xml时那个成员变量的类型type如何写的问题
- Hibernate3.5.4---java application的xml和annotation环境搭建(hibernate.cfg.xml配置文件说明,映射文件Student.hbm.xml说明)
- hibernate.cfg.xml配置文件和hbm.xml配置文件
- Hibernate --- xxx.hbm.xml映射配置文件详解
- Hibernate连接SQL Server2008时候hibernate.cfg.xml和table.hbm.xml文件的配置详情
- 使用hibernate连接mysql数据库正向工程hibernate.cfg.xml文件和xxx.hbm.xml配置文件
- 关于hibernate的hibernate.cfg.xml配置文件包含 .hbm.xml配置文件的路径写法
- eclipse中hibernate配置*.hbm.xml文件和hibernate.cfg.xml文件使其能自动提示