Skip to content

Commit

Permalink
Several Entities connected(Appointment, PetOwner, Veterinarian, Pet)
Browse files Browse the repository at this point in the history
  • Loading branch information
FruTooTi committed Dec 9, 2023
1 parent ee250eb commit 5130a31
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 25 deletions.
20 changes: 8 additions & 12 deletions src/main/java/Entities/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
@Table(name="Appointment")
public class Appointment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int AppointmentID;
@ManyToOne
@JoinColumn(name="PetOwnerID",referencedColumnName = "PetOwnerID")
@JoinColumn(name = "PetOwnerID", referencedColumnName = "PetOwnerID")
private PetOwner PetOwnerID;

@ManyToOne
@JoinColumn(name="VetID",referencedColumnName = "VetID")
@JoinColumn(name = "VetID", referencedColumnName = "VetID")
private Veterinarian VetID;
private DateTimeLiteralExpression.DateTime AppointmentDate;
private int PetID;
@ManyToOne
@JoinColumn(name = "PetID", referencedColumnName = "PetID")
private Pet PetID;
public int getAppointmentID() {
return AppointmentID;
}
Expand Down Expand Up @@ -48,16 +50,10 @@ public DateTimeLiteralExpression.DateTime getAppointmentDate() {
public void setAppointmentDate(DateTimeLiteralExpression.DateTime appointmentDate) {
AppointmentDate = appointmentDate;
}

public int getPetID() {
public Pet getPetID() {
return PetID;
}

public void setPetID(int petID) {
public void setPetID(Pet petID) {
PetID = petID;
}




}
52 changes: 52 additions & 0 deletions src/main/java/Entities/Pet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package Entities;

import jakarta.persistence.*;

import java.util.List;

@Entity
@Table(name = "Pet")
public class Pet {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int PetID;
private String PetName;
private int Age;
@ManyToOne
@JoinColumn(name = "PetTypeID", referencedColumnName = "PetTypeID")
private PetType PetTypeID;
private String Description;
@OneToMany(mappedBy = "Appointments")
private List<Appointment> Appointments;

public int getPetID() {
return PetID;
}
public void setPetID(int petID) {
PetID = petID;
}
public String getPetName() {
return PetName;
}
public void setPetName(String petName) {
PetName = petName;
}
public int getAge() {
return Age;
}
public void setAge(int age) {
Age = age;
}
public PetType getPetTypeID() {
return PetTypeID;
}
public void setPetTypeID(PetType petTypeID) {
PetTypeID = petTypeID;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
}
12 changes: 9 additions & 3 deletions src/main/java/Entities/PetOwner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

import jakarta.persistence.*;

import java.util.List;

@Entity
@Table(name = "PetOwner")
public class PetOwner{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int PetOwnerID;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "UserID", referencedColumnName = "UserID")
private User UserID;
private User User;
private int PetID;

private int VetID;
@ManyToOne
@JoinColumn(name = "VetID", referencedColumnName = "VetID")
private Veterinarian Vet;
@OneToMany(mappedBy = "Appointment")
private List<Appointment> Appointments;
}
7 changes: 5 additions & 2 deletions src/main/java/Entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@Table(name = "User")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int UserID;
private String Name;
private String Surname;
Expand All @@ -14,9 +15,9 @@ public class User {
@ManyToOne
@JoinColumn(name = "UserTypeID", referencedColumnName = "UserTypeID")
private UserType UserTypeID;
@OneToOne(mappedBy = "Veterinarian", cascade = CascadeType.ALL)
@OneToOne(mappedBy = "Veterinarian")
private Veterinarian Vet;
@OneToOne(mappedBy = "PetOwner", cascade = CascadeType.ALL)
@OneToOne(mappedBy = "PetOwner")
private PetOwner Owner;

public int getUserID() {
Expand All @@ -25,9 +26,11 @@ public int getUserID() {
public void setUserID(int userID) {
UserID = userID;
}

public String getName() {
return Name;
}

public void setName(String name) {
Name = name;
}
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/Entities/Veterinarian.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@

import jakarta.persistence.*;

import java.util.List;

@Entity
@Table(name = "Veterinarian")
public class Veterinarian{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int VetID;
@OneToOne
private User UserID;
@OneToMany(mappedBy = "PetOwner")
private List<PetOwner> PetOwners;
private String Clinic;
@OneToMany(mappedBy = "Appointment")
private List<Appointment> Appointments;

public String getClinic() {
return Clinic;
}
public void setClinic(String clinic) {
Clinic = clinic;
}
public User getUserID() {
return UserID;
}
public void setUserID(User userID) {
UserID = userID;
}
public int getVetID() {
return VetID;
}
public void setVetID(int vetID) {
VetID = vetID;
}
public List<PetOwner> getPetOwners() {
return PetOwners;
}
public void setPetOwners(List<PetOwner> petOwners) {
PetOwners = petOwners;
}
}

0 comments on commit 5130a31

Please sign in to comment.