<span style="font-size:18px;"><span style="font-size:24px;">@Entity//代表实体类
@Table(name="student")//生成的目标表
public class Student {
@Id//表示主键
/*主键生成策略*/ /*类型为自增长*/
@GeneratedValue(strategy=GenerationType.AUTO)
Integer id;
@Column(nullable=false,unique=true,length=20)
String sname;
/*
* @JoinTable配置中间表
* joinColumns配置自己在关系表中的外键
* inverseJoinColumns配置对方在关系表中的外键
*/
@JoinTable(name="student_cource",
joinColumns={@JoinColumn(name="student_id")},
inverseJoinColumns={@JoinColumn(name="cource_id")})
@ManyToMany//表示多对多关系
Set<Cource> cources = new HashSet<Cource>()</span>;</span>
<span style="font-size:18px;"><span style="font-size:24px;">@Entity//代表实体类
@Table(name="student")//生成的目标表
public class Student {
@Id//表示主键
/*主键生成策略*/ /*类型为自增长*/
@GeneratedValue(strategy=GenerationType.AUTO)
Integer id;
@Column(nullable=false,unique=true,length=20)
String sname;
/*
* @JoinTable配置中间表
* joinColumns配置自己在关系表中的外键
* inverseJoinColumns配置对方在关系表中的外键
*/
@JoinTable(name="student_cource",
joinColumns={@JoinColumn(name="student_id")},
inverseJoinColumns={@JoinColumn(name="cource_id")})
@ManyToMany//表示多对多关系
Set<Cource> cources = new HashSet<Cource>()</span>;</span>