t3单向多对多

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

<hibernate-mapping>

	<class name="com.tudou.hibernates.e2.Student" table="tb_student">
		<id name="stu_id" type="java.lang.Integer" column="stu_id">
			<generator class="native">
			</generator>
		</id>
		<property name="stuName" />
		<set name="course" table="stu_course" cascade="save-update">
			<key>
				<column name="stu_id"></column>
			</key>
			<many-to-many class="com.tudou.hibernates.e2.Course"
				column="cid" />
		</set>
	</class>
</hibernate-mapping>



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

<hibernate-mapping>

	<class name="com.tudou.hibernates.e2.Course" table="tb_course">
		<id name="cid" type="java.lang.Integer" column="cid">
			<generator class="native" />
		</id>
		<property name="courseName"></property>
	</class>
</hibernate-mapping>

package com.tudou.hibernates.e2;

import java.util.HashSet;
import java.util.Set;

public class Course {
	private int cid;
	private String courseName;

	public int getCid() {
		return cid;
	}

	public void setCid(int cid) {
		this.cid = cid;
	}

	public String getCourseName() {
		return courseName;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

}

package com.tudou.hibernates.e2;

import java.util.HashSet;
import java.util.Set;

public class Student {
	private int stu_id;
	private String stuName;
	private Set<Course> course = new HashSet<Course>();

	public int getStu_id() {
		return stu_id;
	}

	public void setStu_id(int stuId) {
		stu_id = stuId;
	}

	public String getStuName() {
		return stuName;
	}

	public void setStuName(String stuName) {
		this.stuName = stuName;
	}

	public Set<Course> getCourse() {
		return course;
	}

	public void setCourse(Set<Course> course) {
		this.course = course;
	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值