关于Hibernate的映射文件多对多怎么使用(many-to-many)
1.我是应该在user.hbm.xml和sk.hbm.xml里都使用标签,还是只要其中一个使用呢...(如果要两边都能互相修改的话)
2.听说使用会自动生成中间表,我的user_sk表是不是多余的???
3.我的ID是自动增长的,在写bean文件和映射文件时有哪些要注意的...
4.我是不是要在user的bean和sk的bean中各自创建一个对方的set数组呢...
谢谢大家为小弟解惑QAQ
以下是我的数据库,
用户表:ID、密码、姓名、年龄、性别、权限值
课程:课程ID、课程名、用户ID、
授课:授课ID、课程ID、时间、地点、
关系:用户ID、授课ID、
create table user(
id int AUTO_INCREMENT primary key,
name char(20),
pass char(20),
age int,
sex int,
qx int
)AUTO_INCREMENT=0;
create table kc(
kcid int AUTO_INCREMENT primary key,
name char(20),
id int
)AUTO_INCREMENT=1;
create table sk(
skid int AUTO_INCREMENT primary key,
kcid int,
date char(30),
place char(30)
)AUTO_INCREMENT=1;
create table user_sk(
id int,
skid int
);
alter table kc add ( constraint fk_kc_user foreign key(id) references user(id) );
alter table sk add ( constraint fk_sk_kc foreign key(kcid) references kc(kcid) );
alter table user_sk add ( constraint fk_uk_user foreign key(id) references user(id) );
alter table user_sk add ( constraint fk_uk_sk foreign key(skid) references sk(skid) );