一对多hibernate 添加数据(二)

<?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">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="dao.app.HuntMethod" table="hunt_method" catalog="test">
        <id name="huntMethodId" type="integer">
            <column name="hunt_method_id" />
            <generator class="increment"></generator>
        </id>
        <many-to-one name="customer" class="dao.app.Customer"  fetch="select">
            <column name="customer_id" />
        </many-to-one>
        <property name="stuName" type="string">
            <column name="Stu_name" length="40" not-null="true" />
        </property>
        <property name="schoolName" type="string">
            <column name="School_name" length="60" not-null="true" />
        </property>
        <property name="huntState" type="string">
            <column name="Hunt_state" length="40" />
        </property>
        <property name="jobState" type="string">
            <column name="Job_state" length="40" not-null="true" />
        </property>
        <property name="subject" type="string">
            <column name="subject" length="40" />
        </property>
        <property name="contactName" type="string">
            <column name="Contact_name" length="40" not-null="true" />
        </property>
        <property name="class_" type="string">
            <column name="class" length="20" />
        </property>
        <property name="contactNum" type="string">
            <column name="Contact_num" length="40" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

<?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">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="dao.app.Customer" table="customer" catalog="test">
        <id name="customerId" type="integer">
            <column name="customer_id" />
            <generator class="increment"></generator>
        </id>
        <property name="cname" type="string">
            <column name="cname" length="40" not-null="true" />
        </property>
        <property name="password" type="string">
            <column name="password" length="80" not-null="true" />
        </property>
        <property name="sex" type="integer">
            <column name="sex" not-null="true" />
        </property>
        <property name="bornDate" type="string">
            <column name="Born_date" length="20" not-null="true" />
        </property>
        <property name="school" type="string">
            <column name="school" length="40" not-null="true" />
        </property>
        <property name="subject" type="string">
            <column name="subject" length="40" />
        </property>
        <property name="originAddress" type="string">
            <column name="Origin_address" length="200" />
        </property>
        <property name="class_" type="string">
            <column name="class" length="20" />
        </property>
        <property name="cellphone" type="integer">
            <column name="cellphone" />
        </property>
        <property name="email" type="string">
            <column name="email" length="100" not-null="true" />
        </property>
        <property name="photo" type="string">
            <column name="photo" length="200" />
        </property>
        <property name="certificate" type="string">
            <column name="certificate" length="25" />
        </property>
        <property name="studentId" type="string">
            <column name="Student_id" length="40" />
        </property>
        <property name="nickName" type="string">
            <column name="Nick_name" length="40" />
        </property>
        <property name="huntState" type="string">
            <column name="Hunt_state" length="40" />
        </property>
        <property name="workLimit" type="string">
            <column name="Work_limit" length="40" />
        </property>
        <property name="mydate" type="date">
            <column name="mydate" length="10" />
        </property>
        <set name="applies" inverse="true">
            <key>
                <column name="customer_id" />
            </key>
            <one-to-many class="dao.app.Apply" />
        </set>
        <set name="huntMethods" inverse="true" lazy="false">
            <key>
                <column name="customer_id" />
            </key>
            <one-to-many class="dao.app.HuntMethod" />
        </set>
        <set name="colects" inverse="true">
            <key>
                <column name="customer_id" />
            </key>
            <one-to-many class="dao.app.Colect" />
        </set>
    </class>
</hibernate-mapping>
</pre><pre name="code" class="html">
</pre><p>、、、、、、</p><p>实例源代码:</p><p><pre name="code" class="java">			HuntMethod hM =new HuntMethod();
			copyVoValuetoHM(vo, hM);
			List ls=ctmDao.findByStudentId(vo.getStuID());
			if(ls ==null || ls.size()==0){
				l.info("this StudentID isn`t exist!!");
				return false;
			}else{
			
				Customer ctm=(Customer) ls.get(0);
			
				 hM.setCustomer(ctm);	
				 huntMethodDao.save(hM);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值