我有三个表:create table student(
sid number primary key,   //学号
sname varchar2(20),      //姓名
spass varchar2(20)      //密码

);
create table cource
(
cid number primary key,  //课程号
cname varchar2(20),     //课程名
stutime number        //学时
);
create table sc
(
sid number ,
cid number,
score number,          //分数
staTime date,          //开课时间
constraint pk primary key(sid,cid),
constraint fk_sid foreign key(sid) references student_tyut(sid),
constraint fk_cid foreign key(cid) references cource_tyut(cid)
);
以及对应的三个类:
public class Student implements Serializable{
private int sid;
private String sname;
private String spass;
//省略setter和getter方法
}
public class Cource implements Serializable { private int cid;
private String cname;
private int stuTime;
         //省略setter和getter方法
}
public class StudentCource implements Serializable {
private Student student;
private Cource cource;
private int score;
private Date staTime;
          //省略setter和getter方法
}请问:我的StudentCource.hbm.xml要怎么写啊?hibernate的映射有点糊涂,希望达人赐教~

解决方案 »

  1.   

    感觉用annotation比较简单,xml有点繁琐,这个很容易配的,你上网查查资料...
      

  2.   

    依你缩写的代码看来是多对多的关系.按照多对多来配置就好啦.xml和annotation都有各自的优点,不能否定的其中一个.
      

  3.   

    其实采用配置文件,或者是注解,具体的应用应该看在什么情况下,如果单独的使用hibernate,那就随便啦,如果采用和框架的集成,最好就用配置文件吧,统一的配置和管理,方便
      

  4.   

    StudentCource 与Student、Cource都是一对多的关系,使用one-to-many就OK了吧,annotation就直接@OneToMany,