Fix deleted object would be re-saved by cascade (remove deleted object from associations): [com.wisemapping.model.Collaboration#1651889]

This commit is contained in:
Paulo Gustavo Veiga
2022-10-21 23:06:04 -07:00
parent 4ee62035b8
commit 6cd0f635d5
5 changed files with 27 additions and 25 deletions

View File

@@ -26,6 +26,7 @@ import org.jetbrains.annotations.Nullable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;
@Entity
@Table(name = "COLLABORATION")
@@ -127,16 +128,14 @@ public class Collaboration implements Serializable {
Collaboration that = (Collaboration) o;
if (id != that.id) return false;
if (collaborator != null ? !collaborator.equals(that.collaborator) : that.collaborator != null) return false;
if (mindMap != null ? !mindMap.equals(that.mindMap) : that.mindMap != null) return false;
if (!Objects.equals(collaborator, that.collaborator)) return false;
if (!Objects.equals(mindMap, that.mindMap)) return false;
return role == that.role;
}
@Override
public int hashCode() {
int result = id ^ (id >>> 32);
result = 31 * result + (role != null ? role.hashCode() : 0);
result = 31 * result + (mindMap != null ? mindMap.hashCode() : 0);
return result;
//https://thorben-janssen.com/ultimate-guide-to-implementing-equals-and-hashcode-with-hibernate/
return 13;
}
}

View File

@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
@Entity
@Table(name = "LABEL")
@@ -34,17 +35,22 @@ public class Label implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@NotNull private String title;
@NotNull private String color;
@Nullable private String iconName;
@NotNull
private String title;
@NotNull
private String color;
@Nullable
private String iconName;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="creator_id",nullable = true,unique = true)
@NotNull private User creator;
@JoinColumn(name = "creator_id", nullable = true, unique = true)
@NotNull
private User creator;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="parent_label_id",nullable = true)
@Nullable private Label parent;
@JoinColumn(name = "parent_label_id", nullable = true)
@Nullable
private Label parent;
public void setParent(@Nullable Label parent) {
this.parent = parent;
@@ -104,17 +110,15 @@ public class Label implements Serializable {
if (this == o) return true;
if (!(o instanceof Label)) return false;
Label label = (Label) o;
final Label label = (Label) o;
return id == label.id && creator.getId() == label.creator.getId()
&& !(parent != null ? !parent.equals(label.parent) : label.parent != null);
&& Objects.equals(parent, label.parent);
}
@Override
public int hashCode() {
long result = id;
result = 31 * result + title.hashCode();
result = 31 * result + (creator!=null?creator.hashCode():0);
long result = title.hashCode();
result = 31 * result + (creator != null ? creator.hashCode() : 0);
result = 31 * result + (parent != null ? parent.hashCode() : 0);
return (int) result;
}

View File

@@ -146,7 +146,9 @@ public class Mindmap implements Serializable {
}
public void removedCollaboration(@NotNull Collaboration collaboration) {
collaborations.remove(collaboration);
// https://stackoverflow.com/questions/25125210/hibernate-persistentset-remove-operation-not-working
this.collaborations.remove(collaboration);
collaboration.setMindMap(null);
}
public void removedCollaboration(@NotNull Set<Collaboration> collaborations) {