content: package io.amplicode.data.entities;
  
  import jakarta.persistence.*;
  import lombok.*;
  import org.hibernate.proxy.HibernateProxy;
  
  import java.util.LinkedHashSet;
  import java.util.Objects;
  import java.util.Set;
  
  @Getter
  @Setter
  @ToString
  @RequiredArgsConstructor
  @Entity
  @Table(name = "users")
  public class User {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", nullable = false)
      private Long id;
  
      @OneToMany(mappedBy = "user", orphanRemoval = true)
      @ToString.Exclude
      private Set<Post> posts = new LinkedHashSet<>();
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "address_id")
      @ToString.Exclude
      private Address address;
  
      @Override
      public final boolean equals(Object o) {
          if (this == o) return true;
          if (o == null) return false;
          Class<?> oEffectiveClass = o instanceof HibernateProxy
                  ? ((HibernateProxy) o).getHibernateLazyInitializer()
                  .getPersistentClass()
                  : o.getClass();
          Class<?> thisEffectiveClass = this instanceof HibernateProxy
                  ? ((HibernateProxy) this).getHibernateLazyInitializer()
                  .getPersistentClass()
                  : this.getClass();
          if (thisEffectiveClass != oEffectiveClass) return false;
          User user = (User) o;
          return getId() != null && Objects.equals(getId(), user.getId());
      }
  
      @Override
      public final int hashCode() {
          return this instanceof HibernateProxy
                  ? ((HibernateProxy) this).getHibernateLazyInitializer()
                  .getPersistentClass()
                  .hashCode()
                  : getClass().hashCode();
      }
  }
  