Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0
Mapping documents:
<hibernate-mapping package="com.previtec.questionario">
<class name="ControleAcao" table="ControleAcao">
<composite-id>
<key-many-to-one class="Pergunta" column="Pergunta" name="pergunta"/>
<key-many-to-one class="Acao" column="Acao" name="acao"/>
<key-many-to-one class="com.previtec.regra.Objeto" column="Objeto" name="objeto"/>
</composite-id>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.previtec.questionario">
<class name="Acao" table="Acao" discriminator-value="not null">
<id column="Acao" name="acaoID" type="integer">
<generator class="identity"/>
</id>
<discriminator column="TipoAcao" type="integer"/>
<!--set inverse="true" lazy="true" name="controlesAcao" cascade="save-update">
<key column="Acao"/>
<one-to-many class="ControleAcao"/>
</set-->
<subclass name="GeracaoPergunta" discriminator-value="0" >
<many-to-one name="Pergunta" class="Pergunta" cascade="save-update" column="PerguntaGerada"/>
</subclass>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
Name and version of the database you are using: SQL Server 2000
Hi ... First, sorry for my english... I'm brazilian
I have a class Acao whith a subclass GeracaoPergunta (In the future will be more) and when I try to get a Acao from "ControleAcao" (Acao one of ControleAcao pks) I get a error casting it to GeracaoPergunta.
When I load Acao using session.load... the type retrieved is the subclass type ... Ok
When I get Acao from "ControleAcao" it's impossible to cast it to the subclass...
Acao is a abstract class.
Example that works:
Code:
public void testInheritence() {
try {
Session s = Ambiente.getInstance().getSession();
Object object = s.load(Acao.class, 3);
assertNotNull(object);
System.out.println("Pro Christian acreditar:" + object.getClass().toString());
if (!(object instanceof GeracaoPergunta))
{
fail("Classe deveria ser do tipo GeracaoPergunta");
}
} catch (Exception err) {
err.printStackTrace();
}
}
Example that not works:
Code:
public void testAcoes() {
Session s = Ambiente.getInstance().getSession();
Pergunta p = (Pergunta) s.load(Pergunta.class, 4);
Objeto o = (Objeto) s.load(Objeto.class, 8);
List controles = ControleAcao.getDAO().getControleAcaoList(p, o);
for (Object controle : controles) {
Acao acao = controle.getAcao();
if (!(acao instanceof GeracaoPergunta)) {
fail("Must be GeracaoPergunta... but is: " + acao.getClass().toString());
}
}
}
I'm going crazy with that !! :/
Any help will be apreciated, thanks
Marcelo