Hello all! Can anybody help me to resolve this problem?
Example:
Code:
class A {
ISet lines; // contents objects of B1 & B2 classes
...}
class B {
int b_field;
...}
class B1 : B {
int b1_field;
...}
class B2 : B {
int b2_field;
...}
So, B1 & B2 inherite from B and have one specific field each.
I map class A (TABLE_A) this way:
Code:
<set name="lines" lazy="true"...>
<key column="..." />
<one-to-many class="B" />
</set>
Classes B1 & B2 are mapped as subclasses in mapping for B (TABLE_B).
This is a typical situation and it works well. But what will you do, if you want to write a query for class A?!
Example:
Code:
ICriteria criteria = session.CreateCriteria(typeof(A))
.CreateCriteria("Lines")
.Add(Expression.Like("b_field", "...", MatchMode.Anywhere))
.Add(Expression.Like("b1_field", "...", MatchMode.Anywhere))
.Add(Expression.Like("b2_field", "...", MatchMode.Anywhere));
You will get the error that the 'b1_field' cannot be resolved in class B2 and b2_field in B1.
What to do???
And some extra question from me as a lamer: for illustrated createria (if delete two last rows) hibernate creates SQL query and use INNER join for TABLE_A and TABLE_B. How to force it use LEFT join?