日期:2014-05-20 浏览次数:20736 次
<hibernate-mapping> <class name="com.itcast.entity.Dept" table="dept" schema="dbo" catalog="demo" lazy="false"> <id name="deptid" type="java.lang.String"> <column name="deptid" length="50" /> <generator class="assigned" /> </id> <property name="detname" type="java.lang.String"> <column name="detname" length="50" not-null="true" /> </property> <property name="descrip" type="java.lang.String"> <column name="descrip" length="50" /> </property> <set name="students" inverse="true"> <key> <column name="deptno" length="50" not-null="true" /> </key> <one-to-many class="com.itcast.entity.Student" /> </set> </class> </hibernate-mapping>
<hibernate-mapping> <class name="com.itcast.entity.Student" table="student" schema="dbo" catalog="demo"> <id name="id" type="java.lang.String"> <column name="id" length="50" /> <generator class="assigned" /> </id> <many-to-one name="dept" class="com.itcast.entity.Dept" fetch="select"> <column name="deptno" length="50" not-null="true" /> </many-to-one> <property name="name" type="java.lang.String"> <column name="name" length="50" not-null="true" /> </property> <property name="sex" type="java.lang.String"> <column name="sex" length="2" not-null="true" /> </property> <property name="birthday" type="java.util.Date"> <column name="birthday" length="23" not-null="true" /> </property> </class> </hibernate-mapping>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"><value>net.sourceforge.jtds.jdbc.Driver</value></property> <property name="url"> <value>jdbc:jtds:sqlserver://localhost:1433;databasename=demo</value></property> <property name="username"><value>sa</value></property> <property name="password"><value>sa</value></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean> <bean id="Dao" class="com.itcast.dao.Dao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> </beans>