Hi,
I'm trying to implement the inheritance using the "table per class heirarchy" strategy and getting a Class Cast Exception. Not sure what I'm missing. Here's my table structure:
create table LIST_OF_VALUES_MASTER
(
value_id smallint not null,
value_group varchar(2) not null,
value_desc varchar(15),
primary key (value_id,value_group)
);
VALUE_ID|VALUE_GROUP|VALUE_DESC
-------------------------
1 |1 |Sev-1
2 |1 |Sev-2
3 |1 |Sev-3
4 |1 |Sev-4
1 |2 |Production
2 |2 |Adoption
Hibernate version: 3.0
Mapping documents:
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.e3tickets.ListOfValuesMaster" table="LIST_OF_VALUES_MASTER" schema="APP">
<id name="valueId" type="integer">
<column name="VALUE_ID" />
<generator class="assigned" />
</id>
<discriminator column="VALUE_GROUP" type="string"/>
<property name="valueDesc" type="string">
<column name="VALUE_DESC" length="15" />
</property>
<subclass name="com.e3tickets.Severity" discriminator-value="1">
<property name="valueGroup" type="integer" insert="false" update="false">
<column name="VALUE_GROUP"/>
</property>
</subclass>
<subclass name="com.e3tickets.E3Environment" discriminator-value="2">
<property name="valueGroup" type="integer" insert="false" update="false">
<column name="VALUE_GROUP"/>
</property>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction tx = s.beginTransaction();
IssueMaster issue = new IssueMaster();
Severity severity = new Severity();
severity = (Severity)s.get(Severity.class,new Integer(1));
E3Environment env;
E3Environment obj = s.get(E3Environment.class,new Integer(1));
Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.ClassCastException: com.e3tickets.Severity
Name and version of the database you are using:
Derby
The generated SQL (show_sql=true):
select severity0_.VALUE_ID as VALUE1_0_, severity0_.VALUE_DESC as VALUE3_2_0_, severity0_.VALUE_GROUP as VALUE2_2_0_ from APP.LIST_OF_VALUES_MASTER severity0_ where severity0_.VALUE_ID=? and severity0_.VALUE_GROUP='1'
Definition of Severity and Environment class
public class E3Environment extends ListOfValuesMaster {
public static final int ENV_PROD =1;
public static final int ENV_ADOP =2;
}
public class Severity extends ListOfValuesMaster {
public static final int SEV_1=1;
public static final int SEV_2=2;
public static final int SEV_3=3;
public static final int SEV_4=4;
}
public class ListOfValuesMaster implements java.io.Serializable {
// Fields
private int valueId;
private int valueGroup;
private String valueDesc;
...< getters and setters>
}
|