Skip to content

Commit

Permalink
feat: create join connection between _user and _pet table
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsbalazs committed Aug 30, 2024
1 parent d86d62d commit a9fd334
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.greenfoxacademy.backend.models;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.util.Date;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -34,4 +37,8 @@ public class Pet {
private Date petBirthDate;
private Date lastCheckUp;
private Date nextCheckUp;
}

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "petOwner_Id")
private User petOwner;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.greenfoxacademy.backend.models;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -38,6 +42,9 @@ public class User implements UserDetails {
private String password;
private UUID verificationId;

@OneToMany(mappedBy = "petOwner", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Pet> pets = new ArrayList<>();

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return List.of(new SimpleGrantedAuthority("ROLE_USER"));
Expand Down

0 comments on commit a9fd334

Please sign in to comment.