[5b447b0] | 1 | package com.wediscussmovies.project.model;
|
---|
| 2 |
|
---|
| 3 | import com.wediscussmovies.project.model.relation.MovieLikes;
|
---|
| 4 | import com.wediscussmovies.project.model.relation.MovieActors;
|
---|
| 5 | import com.wediscussmovies.project.model.relation.MovieGenres;
|
---|
| 6 | import com.wediscussmovies.project.model.relation.MovieRates;
|
---|
| 7 | import lombok.Data;
|
---|
[f25e8dd] | 8 | import org.hibernate.annotations.Fetch;
|
---|
[5b447b0] | 9 |
|
---|
| 10 | import javax.persistence.*;
|
---|
| 11 | import java.sql.Date;
|
---|
| 12 | import java.util.Collection;
|
---|
| 13 | import java.util.Comparator;
|
---|
| 14 | import java.util.Objects;
|
---|
| 15 |
|
---|
| 16 | @Entity
|
---|
| 17 | @Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
|
---|
| 18 | @Data
|
---|
| 19 | public class Movie {
|
---|
| 20 | @GeneratedValue(strategy = GenerationType.IDENTITY)
|
---|
| 21 | @Id
|
---|
| 22 | @Column(name = "movie_id")
|
---|
| 23 | private int movieId;
|
---|
| 24 | @Basic
|
---|
| 25 | @Column(name = "title")
|
---|
| 26 | private String title;
|
---|
| 27 | @Basic
|
---|
| 28 | @Column(name = "description")
|
---|
| 29 | private String description;
|
---|
| 30 | @Basic
|
---|
| 31 | @Column(name = "image_url")
|
---|
| 32 | private String imageUrl;
|
---|
| 33 | @Basic
|
---|
| 34 | @Column(name = "airing_date")
|
---|
| 35 | private Date airingDate;
|
---|
| 36 | @Basic
|
---|
| 37 | @Column(name = "imdb_rating")
|
---|
| 38 | private Double imdbRating;
|
---|
| 39 |
|
---|
[f25e8dd] | 40 | @OneToMany(mappedBy = "movie", fetch = FetchType.LAZY)
|
---|
[5b447b0] | 41 | private Collection<MovieActors> actors;
|
---|
| 42 | @OneToMany(mappedBy = "movie")
|
---|
| 43 | private Collection<MovieGenres> genres;
|
---|
| 44 | @OneToMany(mappedBy = "movie")
|
---|
| 45 | private Collection<MovieLikes> likes;
|
---|
| 46 | @OneToMany(mappedBy = "movie")
|
---|
| 47 | private Collection<MovieRates> rates;
|
---|
| 48 |
|
---|
| 49 | @ManyToOne
|
---|
| 50 | @JoinColumn(name = "director_id")
|
---|
| 51 | private Person director;
|
---|
| 52 |
|
---|
| 53 | public Movie() {
|
---|
| 54 |
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public Movie(String title, String description, String imageUrl, Date airingDate,
|
---|
| 58 | Double imdbRating, Person director) {
|
---|
| 59 | this.title = title;
|
---|
| 60 | this.description = description;
|
---|
| 61 | this.imageUrl = imageUrl;
|
---|
| 62 | this.airingDate = airingDate;
|
---|
| 63 | this.imdbRating = imdbRating;
|
---|
| 64 | this.director = director;
|
---|
| 65 |
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | @Override
|
---|
| 69 | public boolean equals(Object o) {
|
---|
| 70 | if (this == o) return true;
|
---|
| 71 | if (o == null || getClass() != o.getClass()) return false;
|
---|
| 72 | Movie movie = (Movie) o;
|
---|
| 73 | return movieId == movie.movieId;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | @Override
|
---|
| 77 | public int hashCode() {
|
---|
| 78 | return Objects.hash(movieId);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle);
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | }
|
---|