Support @Where on @MappedSuperClass

Description

I am trying to annotate @Where(clause = "deleted = 'false'") in @MappedSuperclass. But Hibernate does not support.

@MappedSuperclass
@Where(clause = "deleted = 'false'")
public abstract class BaseEntity<ID extends Serializable> implements Serializable {

public static final String DELETED_COLUMN = "deleted";
public static final String ACTIVE_COLUMN = "active";

/** System generated Serial Version UID. */
private static final long serialVersionUID = 1L;

/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id", nullable = false, updatable = false, columnDefinition = "BIGINT UNSIGNED")
protected ID id;

/** The active. */
@Column(nullable = false, columnDefinition = "BOOLEAN default '1'")
protected boolean active = true;

/** The deleted. */
@Column(nullable = false, columnDefinition = "BOOLEAN default '0'")
protected boolean deleted = false;

/**

  • Gets the id.
    *
    * @return the id
    */
    public ID getId() {
    return id;
    }

/**

  • Gets the active.
    *
    * @return the active
    */
    public boolean getActive() {
    return active;
    }

/**

  • Sets the active.
    *
    * @param active the new active
    */
    public void setActive(boolean active) {
    this.active = active;
    }

/**

  • Gets the deleted.
    *
    * @return the deleted
    */
    public Boolean getDeleted() {
    return deleted;
    }

/**

  • Sets the deleted.
    *
    * @param deleted the new deleted
    */
    public void setDeleted(boolean deleted) {
    this.deleted = deleted;
    }

/*

  • (non-Javadoc)
    *
    * @see java.lang.Object#hashCode()
    */
    @Override
    public int hashCode() {
    int hash = 0;
    hash += (this.getId() != null ? this.getId().hashCode() : 0);

return hash;
}

/*

  • (non-Javadoc)
    *
    * @see java.lang.Object#equals(java.lang.Object)
    */
    @Override
    public boolean equals(Object object) {
    if (this == object) return true;
    if (object == null) return false;
    if (getClass() != object.getClass()) return false;

BaseEntity<?> other = (BaseEntity<?>) object;
if (this.getId() != other.getId() && (this.getId() == null || !this.id.equals(other.id))) {
return false;
}
return true;
}

/*

  • (non-Javadoc)
    *
    * @see java.lang.Object#toString()
    */
    @Override
    public String toString() {
    return this.getClass().getName() + " [ID=" + id + "]";
    }
    }

Environment

Java 1.7, Eclipse 4.3, Spring 3.2.x Hibernate 4.2.8 Mysql 5.6

Activity

Show:
Walker Berry
April 21, 2017, 5:44 PM
Edited

It is happening with the latest version of hibernate.

Not my issue, but i created a test case for this:

https://github.com/wberry/mapped-superclass-inherit-annotation-test-case

The root problem seems to be the usage in org.hibernate.cfg.AnnotationBinder. There are other annotations that also seem to be problematic as well.

sudhakar N
July 10, 2019, 6:30 PM

i am using hibernate version 5.0.x and seeing this problem . @Where has no effect when added to @mappedsuperclass . Is this issue fixed ? if yes can you let me know the version . Thanks in Advance.

Tomas Ludrovan
October 24, 2019, 9:51 PM

Affects Hibernate Core v. 6.0.0.Alpha2 as well.

XunBo Guo
December 13, 2019, 4:27 AM

Hi. Does it has archived or plan?

Ganesh Datta
September 23, 2020, 6:29 AM

Wanted to bump this ticket since it’s still affecting v5+. Makes implementing soft delete quite difficult without support for this.

Assignee

Tomas Ludrovan

Reporter

nagaraj shan

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure