我有两个表Movie和Actor
@Entity
@Table(name="movie")
@Data
public class Movie {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer MovieId;
......
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "actorId", referencedColumnName = "actorId")
private Actor actor;
}
@Entity
@Table(name = "actor")
@Data
public class Actor {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer actorId;
private String firstName;
private String lastName;
@OneToMany(mappedBy = "actor", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Movie> actorMovies = new ArrayList<>();
}
现在在MySql数据库中我有两个表,但我需要transiet table movie_actor。现在我有Movie表和列的actorId并且只插入一个id。我希望有一部电影有许多演员的关系。