数据库的多对多:
数据库中不能直接映射多对多
处理:创建一个桥接表(中间表),将一个多对多关系转换成两个一对多
注:数据库多表联接查询,永远就是二个表的联接查询
hibernate的多对多:
hibernate可以直接映射多对多关联关系(看作两个一对多)
多对多关系注意事项:一定要定义一个主控方
案例:
书本表:t_hibernate_book
书本类型表:t_hibernate_category
关联表:t_hibernate_book_category
表结构:
book表:
category表:
关联表:
1.书本:Book.java
package com.crud.five.entity;
import java.util.HashSet;
import java.util.Set;
public class Book {
private Integer bookId;
private String bookName;
private Float price;
private Set<Category> categorys=new HashSet<Category>();
private Integer initCagetorys=0;
public Integer getInitCagetorys() {
return initCagetorys;
}
public void setIni