Класс актеров
Код: Выделить всё
@Entity
@Table(name = "actor")
public class Actor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, name = "actor_name")
private String actorName;
@ManyToMany(mappedBy = "actor", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set movie = new HashSet();
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getActorName() { return actorName; }
public void setActorName(String actorName) {
this.actorName = actorName;
}
public Set getMovie() {
return movie;
}
public void setMovie(Set movie) {
this.movie = movie;
}
}
Код: Выделить всё
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "movie_actor",
joinColumns = {@JoinColumn(name = "movie_id")},
inverseJoinColumns = {@JoinColumn(name = "actor_id")}
)
Set actor = new HashSet();
........................
public Set getActor () {
return actor;
}
public void setActor(Set actor){
this.actor = actor;
}
Код: Выделить всё
Actor actor = ActorRepository.findByActorName(movie.getActor().getActorName());
movie.setActor(actor);
ActorRepository
Код: Выделить всё
public interface ActorRepository extends JpaRepository {
Set findByActorName(String actorName);
}
Код: Выделить всё
@Service
public class ActorService {
private ActorRepository actorRepository;
@Autowired
public ActorService(ActorRepository actorRepository) {
this.actorRepository = actorRepository;
}
public List getAllActor() {
return actorRepository.findAll();
}
}
Подробнее здесь: https://stackoverflow.com/questions/550 ... ry-problem
Мобильная версия