hibernate 映射

<!-- 单向多对一映射 -->
<hibernate-mapping package="org.zyq.hibernate.domain2">


<class name="Customer" table="t_customer">
<id name="id">
<column name="id"/>
<generator class="native"/>
</id>
<property name="name"/>
<set name="orders" inverse="true" table="t_order" lazy="true">
<key column="customer_id"></key>
<one-to-many class="Order" />
</set>
</class>


    <class name="Order" table="t_order">
    <id name="id">
    <column name="id"/>
    <generator class="native"/>
    </id>
    <property name="date"/>
    <property name="description"/>
    <many-to-one name="customer" column="customer_id" lazy="false">
    </many-to-one>
    </class>

</hibernate-mapping>




<class name="Car" table="t_car">
<id name="id">
<column name="id"/>
<generator class="native"/>
</id>
<property name="brand"/>
<property name="speed"/>
    </class>

<class name="Garage" table="t_garage">
<id name="id">
<column name="id"/>
<generator class="native"/>
</id>
<property name="address"/>
<set name="cars" table="car_garage">
<key column="car_id"/>
<many-to-many class="Car"/>
</set>
</class>



<!-- 多对多关联 -->
<hibernate-mapping package="org.zyq.hibernate.domain3">
<class name="Course" table="t_course">
<id name="id">
<column name="id"/>
<generator class="native"/>
</id>
<property name="name"/>
<set name="stus" table="t_stu_course">
<key column="course_id"></key>
<many-to-many class="Stu" column="stu_id"></many-to-many>
</set>
</class>


    <class name="Stu" table="t_stu">
    <id name="id">
    <column name="id"/>
    <generator class="native"/>
    </id>
    <property name="name"/>
<set name="courses" table="t_stu_course">
<key column="stu_id"></key>
<many-to-many class="Course" column="course_id"></many-to-many>
</set>
    </class>
</hibernate-mapping>




public class Course2 {
private Integer id;
private String name ;
private Set<CourseStudent> courseStudent = new HashSet<CourseStudent>();


public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<CourseStudent> getCourseStudent() {
return courseStudent;
}
public void setCourseStudent(Set<CourseStudent> courseStudent) {
this.courseStudent = courseStudent;
}
}

public class Stu2 {
private Integer id;
private String name ;
private Set<CourseStudent> courseStudent = new HashSet<CourseStudent>();

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<CourseStudent> getCourseStudent() {
return courseStudent;
}
public void setCourseStudent(Set<CourseStudent> courseStudent) {
this.courseStudent = courseStudent;
}

}

public class CourseStudent {
private Integer id;
private Course2 course;
private Stu2 stu;
private Integer score;


public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Course2 getCourse() {
return course;
}
public void setCourse(Course2 course) {
this.course = course;
}
public Stu2 getStu() {
return stu;
}
public void setStu(Stu2 stu) {
this.stu = stu;
}
public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}

}

<hibernate-mapping package="org.zyq.hibernate.domain4">
<class name="Course2" table="t_course2">
<id name="id">
<column name="id"/>
<generator class="native"/>
</id>
<property name="name"/>
<set name="courseStudent" cascade="delete" table="t_stu_course2">
<key column="course_id"></key>
<one-to-many class="CourseStudent"/>
</set>
</class>
    <class name="Stu2" table="t_stu2">
    <id name="id">
    <column name="id"/>
    <generator class="native"/>
    </id>
    <property name="name"/>
    <set name="courseStudent" cascade="none" table="t_stu_course2">
    <key column="stu_id"></key>
    <one-to-many class="CourseStudent"/>
    </set>
    </class>
    <class name="CourseStudent" table="t_stu_course2">
    <id name="id">
    <column name="id"/>
    <generator class="native"/>
    </id>
    <many-to-one name="course" class="Course2" column="course_id"></many-to-one>
    <many-to-one name="stu" class="Stu2" column="stu_id"></many-to-one>
    <property name="score"></property>
    </class>
</hibernate-mapping>



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值