首页 > 解决方案 > 用于插入学生详细信息的休眠应用程序

问题描述

我有一个按以下方式建模的现有数据库:

学生 - 学生 ID(整数)、学生姓名(字符串)、性别(字符串)

CollegeStudent - 学期(弦乐),年级(弦乐)

学生 - 学期(字符串),排名(整数)

我想为上面的类图开发一个 Hibernate 应用程序来插入学生的详细信息。注意:插入 2 个 Student 类型的对象、2 个 CollegeStudent 的对象和 2 个 School Student 的对象。

类图图片链接

现在我正在为这个现有数据库创建休眠实体。我在创建从学生到大学生和学生的多对多映射时遇到了奇怪的问题。有什么建议吗?

在此处输入代码`

    import javax.persistence.*;  
    import org.hibernate.annotations.Table; 
    import javax.persistence.GeneratedValue;
    @Entity  
    @Table(name="STUDENT")  
    public class Student {    
         @Id  
         @GeneratedValue(strategy=GenerationType.AUTO)  


    private int Student_id;

    private String Student_name,Student_gender;

    @ManyToOne(cascade = CascadeType.ALL)
    private CollegeStudent collegeStudent;
    public CollegeStudent getCollegeStudent() {
        return CollegeStudent;
    }

    public void setCollegeStudent(CollegeStudent collegeStudent) {
        this.CollegeStudent = collegeStudent;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    private SchoolStudent schoolStudent;
    public SchoolStudent getSchoolStudent() {
        return SchoolStudent;
    }

标签: javahibernatehibernate-mapping

解决方案


推荐阅读