Hibernate一对多单向关系
业务逻辑:
Teacher类和Student类,假定为一对多的关系,即一个教师有多个学生。
1. 数据库schema
Teachers表:
create table TEACHERS
(
ID NUMBER(10) not null,
TEACHERNAME VARCHAR2(15)
)
alter table TEACHERS
add constraint DERE primary key (ID)
Students表:
create table STUDENTS
(
ID NUMBER(10) not null,
STUDENTNAME VARCHAR2(15),
TEACHER_ID NUMBER(10)
)
alter table STUDENTS
add constraint RERE primary key (ID)
alter table STUDENTS
add constraint FFF foreign key (TEACHER_ID)
references TEACHERS (ID);
2. Teacher.Java和Student.java
Teacher.java
package mypack;