[6e7b472] | 1 | package com.wediscussmovies.project.model;
|
---|
| 2 |
|
---|
[7a0bf79] | 3 | import lombok.Data;
|
---|
| 4 |
|
---|
[6e7b472] | 5 | import javax.persistence.*;
|
---|
| 6 | import java.sql.Date;
|
---|
[2a5d6a3] | 7 | import java.util.Comparator;
|
---|
[6e7b472] | 8 | import java.util.List;
|
---|
| 9 |
|
---|
[7a0bf79] | 10 | @Data
|
---|
[2a5d6a3] | 11 | @Entity
|
---|
| 12 | @Table(name="persons")
|
---|
[6e7b472] | 13 | public class Person {
|
---|
| 14 | @Id
|
---|
| 15 | @GeneratedValue
|
---|
| 16 | private int person_id;
|
---|
| 17 |
|
---|
| 18 | @Column(name="name", length=100, nullable=false, unique=false)
|
---|
| 19 | private String name;
|
---|
| 20 |
|
---|
| 21 | @Column(name="surname", length=100, nullable=false, unique=false)
|
---|
| 22 | private String surname;
|
---|
| 23 |
|
---|
| 24 | @Column(name="type", nullable = false)
|
---|
| 25 | private PersonType personType;
|
---|
| 26 |
|
---|
| 27 | @Column(name="date_of_birth", nullable=false)
|
---|
| 28 | private Date date_of_birth;
|
---|
| 29 |
|
---|
| 30 | @Column(name="image_url", length=300, nullable=false, unique=false)
|
---|
| 31 | private String image_url;
|
---|
| 32 |
|
---|
| 33 | @Column(name="description", length=300, nullable=false, unique=false)
|
---|
| 34 | private String description;
|
---|
| 35 |
|
---|
| 36 | @ManyToMany
|
---|
| 37 | private List<Movie> acts_in;
|
---|
[2a5d6a3] | 38 |
|
---|
| 39 | public Person(String name, String surname, PersonType personType, Date date_of_birth, String image_url, String description) {
|
---|
| 40 | this.name = name;
|
---|
| 41 | this.surname = surname;
|
---|
| 42 | this.personType = personType;
|
---|
| 43 | this.date_of_birth = date_of_birth;
|
---|
| 44 | this.image_url = image_url;
|
---|
| 45 | this.description = description;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public Person() {
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public static Comparator<Person> personComparatorByNameSurname = Comparator.comparing(Person::getName).thenComparing(Person::getSurname);
|
---|
[6e7b472] | 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | /*
|
---|
| 56 | create table persons(
|
---|
| 57 | person_id serial primary key,
|
---|
| 58 | name varchar(100) not null,
|
---|
| 59 | surname varchar(100) not null,
|
---|
| 60 | type char(1) not null,
|
---|
| 61 | date_of_birth date not null,
|
---|
| 62 | image_url varchar(300) not null,
|
---|
| 63 | description varchar(300) not null,
|
---|
| 64 | constraint ck_type check (type ='A' or type='D')
|
---|
| 65 | );
|
---|
| 66 | */ |
---|