I have 3 classes Base
, Child
and Other
defined as follows:
@Entity
@Filter(name = "myFilter", condition = "propBase = 'special'")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Base {
private String propBase;
//Getters, Setters
}
@Entity
public class Child extends Base {
private String propChild;
//Getters, Setters
}
@Entity
public class Other {
@Filter(name = "myFilter", condition = "propBase = 'special'")
private Set<Child> myList;
//Getters, Setters
}
Assume the filter is defined at the package level so it is visible by all the classes that use it.
Using a session with myFilter enabled, I retrieve some instance of Other
from my database. Then, when I try to access the myList
collection, since the collection is declared as lazy, Hibernate tries to fetch the collection from the database. But, there is something that I didn't expect in the generated SQL query: the alias of table Child
is used to prefix the propBase
column, and since this column is not defined in the table Child
(it is defined in Base
), I get the following error:
ERROR JDBCExceptionReporter - Unknown column 'childAlias.propBase' in 'where clause'
According to this thread, it seems to be the expected behavior but I don't understand how it can be. Also, assuming this is the expected behavior, how to use filtering when the condition uses properties defined in base class?
Thanks