java - Unable to get child class values with query using Hibernate Table Per Class Hierarchy -


i have 2 java classes hibernate defined classes defining parent/child relationship "extends" keyword single table. have longtext field in table defining type of child class record relational to. (table per class hierarchy)

i wanting query table , put records associate specific child class child class object.

i tried retrieving list of records parent class list , casting them parent object child child cast, of course , java not allow during run time. (looks pretty during compile time though)

i tried query child class list of child classes properties values ones in child class. of properties corresponding parent class null though child extends parent.

how can query table extended child class. need access members of child class after this.

@dbtablemap ( dbtable = "table_mine", dbtablealias = "tabledef" ) public class parentdefined extends basedata {  @dbprimarykey ( dbcolumn = "id" ) private long id; private string type; .... }  @dbtablemap ( dbtable = "table_mine", dbtablealias = "tabledef", includeparent = true ) public class childdefined extends parentdefined {  public childdefined() {     setdiscriminator("a type 1"); }  private string name; private string overridename;  public string getname() {     return name; } public void setname(string name) {     name = name; } public string getoverridename() {     return overridename; } public void setoverridename(string overridename) {     this.overridename = overridename; }  }  <hibernate-mapping>  <subclass name="childdefined"        extends="parentdefined"       type-value="a type 1">      <property name="name" column="name" type="string" not-null="false"/>     <property name="overridename" column="overridename" type="string"/> </subclass> </hibernate-mapping>  <hibernate-mapping>  <class name="parentdefined"        table="table_mine"        abstract="true"        type-value="0">      <id name="id" column="id">         <generator class="native"/>     </id> <type column="type" type="string" length="256" not-null="true"/>     </class> 

list<parentclass> parents = (query using parent class id); for(parentdefined parent : parents){      childdefined child = (childdefined) parent; //class cast exception }  list<childclass> childs = (query using child class id , type 1); for(childdefined child : childs){      child; //class object has values in childdefined members. members of parentdefined null; } 


Comments