hibenate 다 중 중간 표 양 방향 연결

1957 단어
hibenate 다 중 중간 표 양 방향 연결
      ,                  ,         hibernate       

    :
       
    :  <-->  ,              ,            .
   :   
Annotation:@ManyToMany
XML:<many-to-many>
                     ,        .
    (Teache   Student)
Teacher(id,name,students) 
Set<Student> students=new HashSet<Student>()
Student(id,name,teachers) 
Set<Teacher> teachers = new HashSet<Teacher>();
Annotation  
 Teacher    students   
//                   
@ManyToMany
@JoinTable(name="t_s",
joinColumns={@JoinColumn(name="teacher_id")},
inverseJoinColumns={@JoinColumn(name="student_id")}
)
 Student   teachers     
@ManyToMany(mappedBy="students")
XML    :      ,                    
Teacher     
<set name="students" table="t_s">
<key column="teacher_id"/>
<many-to-many class="com.xxx.Student" column="student_id"/>
</set>
 Student     
<set name="teachers" table="t_s">
<key column="student_id"></key>
<many-to-many class="com.xxx.Teacher" column="teacher_id"/>
</set>
     
create table Student (
id integer not null auto_increment,
name varchar(255),
primary key (id)
)
create table Teacher (
id integer not null auto_increment,
name varchar(255),
primary key (id)
)
create table t_s (//      
teacher_id integer not null,
student_id integer not null,
primary key (teacher_id, student_id)
)
t_s        references      .
t_s(teacher_id, student_id)    ,ID       

@orderby(value="id")

좋은 웹페이지 즐겨찾기