hibernate关于对有联合主键表的增删改查探讨

现在有3张表
学生表Stu
create table Stu(
sid Integer(10) primary key,
sname varchar(45) not null
)

实验表Lib
create table Lib(
lid Integer(2) primary key,
lname varchar(45) not null
)

成绩表Score
create table Score(
sid Integer(10),
lid Integer(2),
score varchar(2),
primary key(sid,lid),
foreign key (sid) references Stu(sid),
foreign key (lid) references Lib (lid)
)

这三张表的POJO分别是
Stu
public class Stu extends ActionForm implements java.io.Serializable {
	private Integer sid;
	private String sname;
	private String spwd;
	private Set scores = new HashSet(0);
}

Lib
public class Lib extends ActionForm implements java.io.Serializable {
	private Integer lid;
	private String lname;
	private Set teas = new HashSet(0);
	private Set scores = new HashSet(0);
}

Score
public class Score extends ActionForm implements java.io.Serializable {
	private ScoreId id;
	private String score;
}

*********************************************************

现在我想实现如下功能:
0.在页面上显示某个学生所选的所有实验及成绩
1.为某个学生添加2个实验及其成绩

发现无从下手,因为代码不知道该从何写起。

因为无法用
List scoreList = ScoreDAO.findBySid(s0001);

大家一起来探讨一下这个问题。

猜你喜欢

转载自gk-168.iteye.com/blog/1035606
今日推荐