I have two entity linked with many to many relationship: Movie and Actor
Movie
public class Movie {
@Id
private String imdbId;
@ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER, targetEntity = Actor.class)
private Set<Actor> actor;
}
Actor
public class Actor {
@Id
private String actorId;
}
It is a restful api and I am posting json to MovieController. My json is:
{
"imdbId": "tt2395424",
"actor" : [{"actorId" : "0001"}, {"actorId" : "0002"}]
}
This is working perfectly fine and the actor is populated automatically. But when I insert a new movie with same actorId it throws error that actor is already present. I am confused because as far as I know Hibernate compares the id before insertion if not present it will insert else just map it. Can you please tell me where I am going wrong?