配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd" default-autowire="byType">
<!-- 配置数据源-连接池 -->
<bean /> -->
<list>
<!-- 给出实体类所在范围 -->
<value>com.oak.entity</value>
</list>
</property>

<!-- 配置参数 -->
<property name="hibernateProperties">
<!-- 集合注入 -->
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- 自动建表key值固定的 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>

<!-- 扫描注解 -->
<context:component-scan base-package="com"></context:component-scan>
<!-- 日志打印 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>

</beans>

映射文件

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- hibernate-mapping标签中有个package属性,表示持久化类所在的包 package="com.oak.pojo"
如果此处加了package属性,则class标签的属性name值只写类名即可,
如果hibernate-mapping标签中没加package属性
则class标签的name值为 全限定名(表名+类名)-->
<hibernate-mapping>
<!-- 对应类和表 -->
<class name="com.oak.entity.Goods" table="T_GOODS">
<!-- 对应的属性和字段 -->
<id name="id" column="id">
<generator class="native"></generator>
</id>
<!-- 给非主属性和非主字段 -->
<property name="goodsname" column="goodsname"></property>
<property name="weight" column="weight"></property>
<property name="price" column="price"></property>
<property name="color" column="color"></property>
<property name="shangtime" column="shangtime" type="java.sql.Date"></property>
<property name="stock" column="stock"></property>

<many-to-one name="brand" class="com.oak.entity.Brand">
<column name="BRANDID"></column>
</many-to-one>

<many-to-one name="smc" class="com.oak.entity.SmallClass">
<column name="SID"></column>
</many-to-one>
</class>
</hibernate-mapping>

相关文章: