I've tried the following with some level of success, but I'm a 'rookie' on hibernate mapping and have not had any hibernate guru critique my approach.
With that said, I have an abstract class and several concrete classes that extend this abstract class. Here's the java classes
Code:
public class abstract Employee {
private int id;
private string name;
private string employeeName;
public get.../set...
}
public class Programmer extends Employee {
}
public class SalesPerson extends Employee {
private BigDecimal commission;
public BigDecimal getCommission();
public void setCommission(BigDecimal comm) { ... }
}
Here's my mapping file using your example classes...
Code:
<class name="Employee" table="employees" discriminator-value="employee" >
<id name="id" column="id">
<generator class="{your choice here}"/>
</id>
<!-- descriminator (must precede properties) -->
<discriminator column="employee_type" type="string" />
<property name="name" column="employee_name" type="string" length="32" not-null="true" access="field"/>
<property name="employeeNumber" column="employee_number" type="string" length="32" not-null="true" access="field"/>
<!-- programmer -->
<subclass name="Programmer"
discriminator-value="programmer">
</subclass>
<!-- Sales person -->
<subclass name="SalesPerson"
discriminator-value="sales">
<property name="commission" column="commission" type="big_decimal" access="field" />
</subclass>
...