I'm trying to migrate a project from 3.5.6-Final to 4.3.5.Final and am running into a problem wrt Filters and subclasses.
We have a simple class hierarchy that has a @Filter annotation on the parent class, as such:
Code:
@MappedSuperclass
@FilterDef(name = FILTER_SOFT_DELETES, defaultCondition = "deleted = 0", parameters = {})
@Filter(name = FILTER_SOFT_DELETES)
public class AuditableEntity {
@Column(name = "deleted", nullable = false, columnDefinition = "numeric(1,0) default 0")
private boolean deleted = false;
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "legal_entity")
public class LegalEntity extends AuditableEntity {
}
@Entity
@Table(name = "person")
public class Person extends LegalEntity {
}
Now when enabling the filter, a where clause gets generated that checks for delete=0 on both the legal_entity and person table!
This is obviously wrong and the query fails. This was not the case in 3.5.6-Final!
During debugging I noticed a couple of things:
The end result is that upon querying for Person, I end up with two identical filters, both being added to the where clause:
Code:
SELECT ... FROM person person0_
INNER JOIN legal_entity person0_1_
ON person0_.id = person0_1_.id
WHERE person0_.deleted = 0
AND person0_1_.deleted = 0
AND person0_.id = ?;
Of course, "person0_1_.deleted = 0" yields a syntax error.
I noticed that a lot of changes were made to filters to enable being able to define filters on subclasses in https://hibernate.atlassian.net/browse/HHH-2394, but it seems this got broken along the way?
Any suggestions?
edit: I was able to confirm this is only a true problem when you have @Inheritance(strategy = InheritanceType.JOINED) specified. If you don't , then the deleted = 0 still gets added as many times are you have concrete classes, but now it's all on the same table... I'm going to go ahead and create a bug report for this.
edit2: bug report created: https://hibernate.atlassian.net/browse/HHH-9257