I have a class hierarchy of 3 Entities, one of which is the superclass for the 
others:

@Entity
@Table(name="PER")
@Inheritance(strategy=InheritanceType.JOINED)
@SequenceGenerator(name="SeqIdPer", sequenceName="SEQIDPER")
public abstract class Person implements Serializable {
...
}

@Entity
@Table(name="PHYPER")
@PrimaryKeyJoinColumn(name="IDPHYPER")
public class PhysicalPerson extends Person {
..
}

@Entity
@Table(name="MORALPER")
@PrimaryKeyJoinColumn(name="IDMORALPER")
public class MoralPerson extends Person {
...
}

When I execute the following JPQL:

       String strPerQuery = "SELECT OBJECT(per) FROM Person per where per.idPer 
= ?";                
                query=em.createQuery(strPerQuery);
                query.setParameter(1, idPerson);
                Person resPer = (Person)query.getSingleResult();

I get an object of the class Person, but I cannot downcast it to any of the 
subclasses. For example, even when I know that the person I sought is an 
instance of PhysicalPerson, the following cast throws a ClassCastException:

          PhysicalPerson phyPer = (PhysicalPerson )resPer;

Even more, when I print the runtime class of the object using 
resPer.getClass(), I get the following class:

mypackage.Person_$$_javassist_16 

Shouldn't the query be polymorphic, and return an object of the subclass?

I'm using JBoss 5 beta 4.

Thanks in advance.
         

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139068#4139068

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139068
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to