Hello Hibernate developers and community people,
I am aware that HQL (in Hibernate 3.2) allows accessing to an association defined on a subclass through its superclass (I will describe in detail below), and I am posting here because I would like to make sure that this was a designed behavior but not incidental. I would appreciate if I could get information from someone who knew the design intention or who could point out a documentation that I had been missing.
Here is a minimal example.
I have three classes. 'AbstractA' and its subclass 'ConcreteA' are mapped to a table by STI strategy. ConcreteA has a many-to-one association to the third class, 'B'. Note this association is defined on ConcreteA so AbstractA knows nothing about it.
Code:
<class name="AbstractA" table="A">
<id name="id"/>
<discriminator column="DISC" type="string"/>
</class>
<subclass name="ConcreteA" extends="AbstractA">
<many-to-one name="b" class="B"/>
</subclass>
<class name="B">
<id name="id"/>
</class>
Upon this mapping and the class definition behind, an HQL below works well:
Code:
select a, b from AbstractA a inner join a.b b
The point is that Hibernate interprets association 'a.b' in the join clause according to the mapping defined for ConcreteA (as I wished) although 'a' is merely an alias of AbstractA. In an object-oriented sense, AbstractA should know nothing about ConcreteA or association 'b'.
As to my code reading of Hibernate, I believe this behavior is intended. I found an explicit code that was searching for the specified property name in subclass's property name closure, not only superclass's, when building SQL AST from HQL AST.
Because I need to rely on this behavior for some reasons, I would like to make sure that my code reading is correct and I could use this safely as Hibernate's designed feature. So far, I have failed to find any documentation about this in the HQL reference. I would appreciate it if someone here could give me a light on it.
Thank you in advance,
Tomoto