Ignore:
Timestamp:
03/09/23 16:11:48 (16 months ago)
Author:
GitHub <noreply@…>
Branches:
main
Children:
0078d84, 4ab3aae
Parents:
8b7dd7f (diff), 264d675 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
SazdovaEkaterina <74919977+SazdovaEkaterina@…> (03/09/23 16:11:48)
git-committer:
GitHub <noreply@…> (03/09/23 16:11:48)
Message:

Merge pull request #9 from SazdovaEkaterina/fix-foreign-keys

Fix Database Mapping in Models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Pet.java

    r8b7dd7f rc3278ac  
    77import jakarta.persistence.*;
    88import lombok.Data;
     9import lombok.RequiredArgsConstructor;
     10
     11import java.util.List;
    912
    1013@Data
    1114@Entity
     15@RequiredArgsConstructor
    1216@Table(name = "pet")
    1317public class Pet {
     
    1721    @Column(name = "id_pet")
    1822    private Integer id;
     23
     24    @OneToOne
     25    @JoinColumn(name = "id_pet", nullable = false)
     26    private PersonalProfile personalProfile;
    1927
    2028    @Column(name = "url_pet_image", length = 200)
     
    4048
    4149    @Column(name = "can_be_fostered", nullable = false)
    42     private boolean canBeFostered;
     50    private Boolean canBeFostered;
    4351
    44     @Column(name = "id_adoption")
    45     private Integer adoptionId;
     52    @ManyToOne
     53    @JoinColumn(name = "id_adoption")
     54    private Adoption adoption;
    4655
    47     @Column(name = "id_shelter")
    48     private Integer shelterId;
     56    @ManyToOne
     57    @JoinColumn(name = "id_shelter")
     58    private Shelter shelter;
    4959
    50     public Pet(String imageUrl, AgeGroup ageGroup, Size size, String breed, String name, Species species, Gender gender, boolean canBeFostered, Integer adoptionId, Integer shelterId) {
     60    @ManyToMany
     61    @JoinTable(name = "pet_belongs_to_category",
     62            joinColumns = @JoinColumn(name = "id_pet"),
     63            inverseJoinColumns = @JoinColumn(name = "id_category"))
     64    List<Category> categories;
     65
     66    @ManyToMany
     67    @JoinTable(name = "pet_needs_intervention_in_vet_clinic",
     68            joinColumns = @JoinColumn(name = "id_pet"),
     69            inverseJoinColumns = @JoinColumn(name = "id_vet_clinic"))
     70    List<VetClinic> vetClinicsTreatedIn;
     71
     72    @ManyToMany
     73    @JoinTable(name = "pet_needs_therapy",
     74            joinColumns = @JoinColumn(name = "id_pet"),
     75            inverseJoinColumns = @JoinColumn(name = "id_therapy"))
     76    List<Therapy> therapies;
     77
     78    @ManyToMany
     79    @JoinTable(name = "pet_preferably_eats_food",
     80            joinColumns = @JoinColumn(name = "id_pet"),
     81            inverseJoinColumns = @JoinColumn(name = "id_food"))
     82    List<Food> preferredFoods;
     83
     84    public Pet(String imageUrl, AgeGroup ageGroup, Size size, String breed,
     85               String name, Species species, Gender gender, Boolean canBeFostered,
     86               Adoption adoption, Shelter shelter) {
    5187        this.imageUrl = imageUrl;
    5288        this.ageGroup = ageGroup;
     
    5793        this.gender = gender;
    5894        this.canBeFostered = canBeFostered;
    59         this.adoptionId = adoptionId;
    60         this.shelterId = shelterId;
    61     }
    62 
    63     public Pet() {
     95        this.adoption = adoption;
     96        this.shelter = shelter;
    6497    }
    6598}
Note: See TracChangeset for help on using the changeset viewer.