Commit 595e3c93 authored by Administrator's avatar Administrator

Changes pet relation in owner

In order to avoid repeated pets in the relation.
parent c4ab8bb8
...@@ -5,8 +5,9 @@ import static java.util.Collections.unmodifiableCollection; ...@@ -5,8 +5,9 @@ import static java.util.Collections.unmodifiableCollection;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue; import javax.persistence.DiscriminatorValue;
...@@ -28,12 +29,11 @@ public class Owner extends User implements Serializable { ...@@ -28,12 +29,11 @@ public class Owner extends User implements Serializable {
@OneToMany( @OneToMany(
mappedBy = "owner", mappedBy = "owner",
targetEntity = Pet.class,
cascade = CascadeType.ALL, cascade = CascadeType.ALL,
orphanRemoval = true, orphanRemoval = true,
fetch = FetchType.EAGER fetch = FetchType.EAGER
) )
private Collection<Pet> pets; private Set<Pet> pets;
// Required for JPA // Required for JPA
Owner() {} Owner() {}
...@@ -53,7 +53,7 @@ public class Owner extends User implements Serializable { ...@@ -53,7 +53,7 @@ public class Owner extends User implements Serializable {
*/ */
public Owner(String login, String password) { public Owner(String login, String password) {
super(login, password); super(login, password);
this.pets = new ArrayList<>(); this.pets = new HashSet<>();
} }
/** /**
...@@ -72,8 +72,7 @@ public class Owner extends User implements Serializable { ...@@ -72,8 +72,7 @@ public class Owner extends User implements Serializable {
* not valid according to its description. * not valid according to its description.
*/ */
public Owner(String login, String password, Pet ... pets) { public Owner(String login, String password, Pet ... pets) {
super(login, password); this(login, password);
this.pets = new ArrayList<>();
stream(pets).forEach(this::addPet); stream(pets).forEach(this::addPet);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment