11package io .amplicode .data .entities ;
22
33import jakarta .persistence .*;
4- import lombok .Data ;
4+ import lombok .*;
5+ import org .hibernate .proxy .HibernateProxy ;
56
67import java .util .LinkedHashSet ;
8+ import java .util .Objects ;
79import java .util .Set ;
810
9- @ Data
11+ @ Getter
12+ @ Setter
13+ @ ToString
14+ @ RequiredArgsConstructor
1015@ Entity
1116@ Table (name ="users" )
1217public class User {
@@ -16,10 +21,37 @@ public class User {
1621private Long id ;
1722
1823@ OneToMany (mappedBy ="user" ,orphanRemoval =true )
24+ @ ToString .Exclude
1925private Set <Post >posts =new LinkedHashSet <>();
2026
2127@ ManyToOne (fetch =FetchType .LAZY )
2228@ JoinColumn (name ="address_id" )
29+ @ ToString .Exclude
2330private Address address ;
2431
32+ @ Override
33+ public final boolean equals (Object o ) {
34+ if (this ==o )return true ;
35+ if (o ==null )return false ;
36+ Class <?>oEffectiveClass =o instanceof HibernateProxy
37+ ? ((HibernateProxy )o ).getHibernateLazyInitializer ()
38+ .getPersistentClass ()
39+ :o .getClass ();
40+ Class <?>thisEffectiveClass =this instanceof HibernateProxy
41+ ? ((HibernateProxy )this ).getHibernateLazyInitializer ()
42+ .getPersistentClass ()
43+ :this .getClass ();
44+ if (thisEffectiveClass !=oEffectiveClass )return false ;
45+ User user = (User )o ;
46+ return getId () !=null &&Objects .equals (getId (),user .getId ());
47+ }
48+
49+ @ Override
50+ public final int hashCode () {
51+ return this instanceof HibernateProxy
52+ ? ((HibernateProxy )this ).getHibernateLazyInitializer ()
53+ .getPersistentClass ()
54+ .hashCode ()
55+ :getClass ().hashCode ();
56+ }
2557}