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;
import static java.util.Objects.requireNonNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
......@@ -28,12 +29,11 @@ public class Owner extends User implements Serializable {
@OneToMany(
mappedBy = "owner",
targetEntity = Pet.class,
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.EAGER
)
private Collection<Pet> pets;
private Set<Pet> pets;
// Required for JPA
Owner() {}
......@@ -53,7 +53,7 @@ public class Owner extends User implements Serializable {
*/
public Owner(String login, String password) {
super(login, password);
this.pets = new ArrayList<>();
this.pets = new HashSet<>();
}
/**
......@@ -72,8 +72,7 @@ public class Owner extends User implements Serializable {
* not valid according to its description.
*/
public Owner(String login, String password, Pet ... pets) {
super(login, password);
this.pets = new ArrayList<>();
this(login, password);
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