ЛР3 без доп задания

This commit is contained in:
ityurner02@mail.ru 2023-04-03 16:29:42 +04:00
parent de105ade49
commit 8baede6bca
6 changed files with 29 additions and 5 deletions

Binary file not shown.

View File

@ -42,8 +42,12 @@ public class Collection {
if (films == null){
films = new ArrayList<>();
}
if (!this.films.contains(film)) {
this.films.add(film);
film.addCollections(this);
}
}
public void removeFilm(Film film){
if(films != null){

View File

@ -1,5 +1,8 @@
package ru.ulstu.is.lab1.DataBase.model;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import javax.persistence.*;
import java.util.List;
@ -12,12 +15,15 @@ public class Film {
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@ManyToMany(fetch = FetchType.EAGER)
@ManyToMany
@LazyCollection(LazyCollectionOption.FALSE)
@JoinTable(name="films_genres",
joinColumns = @JoinColumn(name="film_id"),
inverseJoinColumns = @JoinColumn(name="genre_id")
)
private List<Genre> genres;
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "films")
private List<Collection> collections;
public Film() {
}
@ -42,6 +48,7 @@ public class Film {
if (genres == null){
genres = new ArrayList<>();
}
if (!this.genres.contains(genre))
this.genres.add(genre);
}
@ -55,6 +62,16 @@ public class Film {
return genres;
}
public List<Collection> getCollections() {
return collections;
}
public void addCollections(Collection collection) {
if(this.collections==null)
collections=new ArrayList<>();
collections.add(collection);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -11,8 +11,6 @@ public class Genre {
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "genres")
private List<Film> films;
public Genre() {
}

View File

@ -9,6 +9,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
@Service
@ -89,4 +91,6 @@ public class FilmService {
public void deleteAllFilms() {
em.createQuery("delete from Film").executeUpdate();
}
//сделать запрос отбора фильмов по жанру
}

View File

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.math.BigInteger;
import java.util.List;
@SpringBootTest