Hi, I am running into a problem when using HQL (or Criteria API) with Hibernate 3, I've been reading some of the posts but I am not sure yet if it's possible to do what I want.
The question is, given the next mapping:
Code:
<class
name="A"
table="values"
lazy="false">
...
<subclass
name="B"
discriminator-value="1">
<property name="value" type="string">
<column name="string_value" sql-type="text"/>
</property>
</subclass>
<subclass
name="C"
discriminator-value="2">
<property name="value" type="double">
<column name="number_value" />
</property>
</subclass>
</class>
and the next classes:
Code:
public abstract class A {
public abstract Object getValue();
public abstract void setValue(Object obj);
}
public class B extends A {
private String value;
public Object getValue() {
return value;
}
public voud setValue(Object obj) {
this.value = (String) obj;
}
}
public class C extends A {
private Integer value;
public Object getValue() {
return value;
}
public voud setValue(Object obj) {
this.value = (Integer) obj;
}
}
Is it possible to execute polymorphic HQL queries such as the next ones?:
Code:
from A as a where a.class = B and a.value = 'test' // It should check the string_value field
from A as a where a.class = C and a.value = 1 // It should check the number_value field
In my tests Hibernate doesn't seem "smart" enough to choose the right field of the table, but maybe I am doing something wrong or it's simply not possible.
Could anyone give me any clue about this?
Thanks![/code]