For migrating from eclipse link to hibernate, I am looking for the equivalent of eclipse link annotation @AdditionalCriteria
in Hibernate at @MappedSupperClass
BaseEntity
level, to filter logically deleted records from all entities extending this BaseEntity
.
I had found @Where
annotation. But, this only works at Entity
level and not at BaseEntity. Please let me know if there is any possibility to add this or any other Hibernate annotation to filter BaseEntity
.
@MappedSuperclass
@Where(clause = "DEL_IND = 0") // DOES NOT WORK
public abstract class BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "DEL_IND")
private boolean deleted = Boolean.FALSE;
public boolean getDeleted() {
return deleted;
}
public void setDeleted() {
this.deleted = Boolean.TRUE;
}
}
@Entity
@Table(name = "PERSON")
@Where(clause = "DEL_IND = 0") // THIS WORKS BUT NEEDS TO BE REPEATED IN ALL ENTITIES
public class Person extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "PERSON_ID")
private Integer id;
@Column(name = "LAST_NAME")
private String lastName;
@Column(name = "FIRST_NAME")
private String firstName;
--------------------
getters & setters
--------------------
--------------------
}
You can open a Hibernate JIRA issue for this. The only workaround is to manually add the @Where
annotation to all your entities or use filters.
With filters you have the option of dynamically enable/disable them, which is useful since you might want to fetch a deleted item sometimes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With