Skip to content

Commit

Permalink
Relationships between Client-Shelter, ManyToMany
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbogdan committed Feb 27, 2024
1 parent cdd4a22 commit 177cdc5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Client.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package cat.udl.eps.softarch.demo.domain;

import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.Collection;
import java.util.Set;

@EqualsAndHashCode(callSuper = true)
@Entity
@Data
public class Client extends User {
@ManyToMany
@JoinTable(
name = "client_shelter",
joinColumns = @JoinColumn(name = "client_id"),
inverseJoinColumns = @JoinColumn(name = "shelter_id")
)
private Set<Shelter> shelters;

@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities(){
return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_CLIENT");
}
}

0 comments on commit 177cdc5

Please sign in to comment.