From 7373d62f862d0d745196b17e646dbcfb34275b02 Mon Sep 17 00:00:00 2001 From: Roman Strobl Date: Mon, 3 Jun 2024 15:45:25 +0200 Subject: [PATCH] Use ProxyUtils in equals methods for entities --- .../security/userdatastore/model/entity/AttachmentEntity.java | 3 ++- .../security/userdatastore/model/entity/DocumentEntity.java | 3 ++- .../security/userdatastore/model/entity/PhotoEntity.java | 3 ++- .../security/userdatastore/model/entity/UserClaimsEntity.java | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/wultra/security/userdatastore/model/entity/AttachmentEntity.java b/src/main/java/com/wultra/security/userdatastore/model/entity/AttachmentEntity.java index fa889c0..7070ae7 100644 --- a/src/main/java/com/wultra/security/userdatastore/model/entity/AttachmentEntity.java +++ b/src/main/java/com/wultra/security/userdatastore/model/entity/AttachmentEntity.java @@ -20,6 +20,7 @@ import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; +import org.springframework.data.util.ProxyUtils; import java.io.Serial; import java.io.Serializable; @@ -69,7 +70,7 @@ public class AttachmentEntity implements Serializable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !this.getClass().equals(ProxyUtils.getUserClass(o))) return false; AttachmentEntity that = (AttachmentEntity) o; return document.equals(that.document) && attachmentType.equals(that.attachmentType) && timestampCreated.equals(that.timestampCreated); } diff --git a/src/main/java/com/wultra/security/userdatastore/model/entity/DocumentEntity.java b/src/main/java/com/wultra/security/userdatastore/model/entity/DocumentEntity.java index b8b4382..d2f478c 100644 --- a/src/main/java/com/wultra/security/userdatastore/model/entity/DocumentEntity.java +++ b/src/main/java/com/wultra/security/userdatastore/model/entity/DocumentEntity.java @@ -20,6 +20,7 @@ import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; +import org.springframework.data.util.ProxyUtils; import java.io.Serial; import java.io.Serializable; @@ -74,7 +75,7 @@ public class DocumentEntity implements Serializable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !this.getClass().equals(ProxyUtils.getUserClass(o))) return false; DocumentEntity that = (DocumentEntity) o; return userId.equals(that.userId) && documentType.equals(that.documentType) && dataType.equals(that.dataType) && documentDataId.equals(that.documentDataId); } diff --git a/src/main/java/com/wultra/security/userdatastore/model/entity/PhotoEntity.java b/src/main/java/com/wultra/security/userdatastore/model/entity/PhotoEntity.java index 0e1b45a..023c822 100644 --- a/src/main/java/com/wultra/security/userdatastore/model/entity/PhotoEntity.java +++ b/src/main/java/com/wultra/security/userdatastore/model/entity/PhotoEntity.java @@ -20,6 +20,7 @@ import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; +import org.springframework.data.util.ProxyUtils; import java.io.Serial; import java.io.Serializable; @@ -69,7 +70,7 @@ public class PhotoEntity implements Serializable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !this.getClass().equals(ProxyUtils.getUserClass(o))) return false; PhotoEntity that = (PhotoEntity) o; return document.equals(that.document) && photoType.equals(that.photoType) && timestampCreated.equals(that.timestampCreated); } diff --git a/src/main/java/com/wultra/security/userdatastore/model/entity/UserClaimsEntity.java b/src/main/java/com/wultra/security/userdatastore/model/entity/UserClaimsEntity.java index 67e9a6c..4fe3e3d 100644 --- a/src/main/java/com/wultra/security/userdatastore/model/entity/UserClaimsEntity.java +++ b/src/main/java/com/wultra/security/userdatastore/model/entity/UserClaimsEntity.java @@ -20,6 +20,7 @@ import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; +import org.springframework.data.util.ProxyUtils; import java.time.LocalDateTime; import java.util.Objects; @@ -56,7 +57,8 @@ public class UserClaimsEntity { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof UserClaimsEntity that)) return false; + if (o == null || !this.getClass().equals(ProxyUtils.getUserClass(o))) return false; + UserClaimsEntity that = (UserClaimsEntity) o; return userId.equals(that.userId); }