Using a scope defined Override for a JPA Entity

27 Views Asked by At

I am currently confronted with following Scenario:

I would like to override the equals and hashcode functions of all entities in my project and would not like to re implement the @Overrides for all Entity-classes I have. Is there a common/lnown soultion for this?

I was thinking of something along the lines of:

public class CustomJPAEntity {

    @Override
    public boolean equals( Object obj) {
...
    }

    @Override
    public int hashCode()  {
...
    }

No global fields for Entities are defined here and I want to use these Overrides in my Entity classes

@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "myentity")
public class MyEntity extends CustomJPAEntity {

    @Id
    @Column(name = "myid", nullable = false)
    private String myid;

    @Column(name = "date")
    private String requestDate;

...

MyEntity should take the defined @Overrides from the CustomJPAEntity instead of the standard JPA functions. I am open for any alternative suggestions :)

My efforts so far have been to no avail.Even tried @MappedSuperclass. Hope you guys can help :)

0

There are 0 best solutions below