如何创建转换表

时间:2018-06-03 11:18:28

标签: java spring hibernate jpa

我有两个表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。我希望有一部电影有许多演员的关系。

0 个答案:

没有答案