Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;

import java.util.HashSet;
Expand Down Expand Up @@ -48,14 +49,15 @@ public class AuthorEntity {
private Set<BookMetadataEntity> bookMetadataEntityList = new HashSet<>();

@Override
public boolean equals(Object o) {
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AuthorEntity that)) return false;
return id != null && Objects.equals(id, that.id);
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
AuthorEntity that = (AuthorEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
return getClass().hashCode();
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}
}
15 changes: 15 additions & 0 deletions backend/src/main/java/org/booklore/model/entity/BookEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.booklore.convertor.BookRecommendationIdsListConverter;
import org.booklore.model.dto.BookRecommendationLite;
import org.booklore.model.enums.BookFileType;
import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.LazyGroup;

Expand All @@ -14,6 +15,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

@Entity
Expand Down Expand Up @@ -131,4 +133,17 @@ public BookFileEntity getPrimaryBookFile() {
public boolean hasFiles() {
return bookFiles != null && !bookFiles.isEmpty();
}

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
BookEntity that = (BookEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ public class BookLoreUserEntity {

@BatchSize(size = 20)
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "user_library_mapping",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "library_id")
)
@JoinTable(name = "user_library_mapping", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "library_id"))
@Builder.Default
private Set<LibraryEntity> libraries = new HashSet<>();

Expand Down Expand Up @@ -97,15 +93,15 @@ public void prePersist() {
}

@Override
public boolean equals(Object o) {
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
BookLoreUserEntity that = (BookLoreUserEntity) o;
return id != null && Objects.equals(id, that.id);
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;

import java.util.HashSet;
Expand Down Expand Up @@ -30,15 +31,16 @@ public class CategoryEntity {
private Set<BookMetadataEntity> bookMetadataEntityList = new HashSet<>();

@Override
public boolean equals(Object o) {
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CategoryEntity that)) return false;
return id != null && Objects.equals(id, that.id);
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
CategoryEntity that = (CategoryEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
return getClass().hashCode();
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.booklore.model.enums.MetadataSource;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;
import java.util.*;

Expand Down Expand Up @@ -75,15 +76,16 @@ public class LibraryEntity {
private MetadataSource metadataSource = MetadataSource.EMBEDDED;

@Override
public boolean equals(Object o) {
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof LibraryEntity that)) return false;
return id != null && Objects.equals(id, that.id);
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
LibraryEntity that = (LibraryEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
return getClass().hashCode();
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}

}
12 changes: 7 additions & 5 deletions backend/src/main/java/org/booklore/model/entity/MoodEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;

import java.util.HashSet;
Expand Down Expand Up @@ -30,15 +31,16 @@ public class MoodEntity {
private Set<BookMetadataEntity> bookMetadataEntityList = new HashSet<>();

@Override
public boolean equals(Object o) {
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MoodEntity that)) return false;
return id != null && Objects.equals(id, that.id);
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
MoodEntity that = (MoodEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
return getClass().hashCode();
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}
}

16 changes: 15 additions & 1 deletion backend/src/main/java/org/booklore/model/entity/ShelfEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
import org.booklore.convertor.SortConverter;
import org.booklore.model.dto.Sort;
import org.booklore.model.enums.IconType;
import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Formula;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
@Entity
@Table(name = "shelf")
public class ShelfEntity {
Expand Down Expand Up @@ -57,4 +58,17 @@ public class ShelfEntity {
)
@Builder.Default
private Set<BookEntity> bookEntities = new HashSet<>();

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
ShelfEntity that = (ShelfEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}
}
12 changes: 7 additions & 5 deletions backend/src/main/java/org/booklore/model/entity/TagEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize;

import java.util.HashSet;
Expand Down Expand Up @@ -30,14 +31,15 @@ public class TagEntity {
private Set<BookMetadataEntity> bookMetadataEntityList = new HashSet<>();

@Override
public boolean equals(Object o) {
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TagEntity that)) return false;
return id != null && Objects.equals(id, that.id);
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
TagEntity that = (TagEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
return getClass().hashCode();
public final int hashCode() {
return Hibernate.getClass(this).hashCode();
}
}
Loading