I get the following exception when I tried to use annotations with joined subclass inheritance:
Code:
Exception in thread "main" java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:679)
at org.hibernate.cfg.AnnotationBinder.processElementsOfAClass(AnnotationBinder.java:532)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:382)
at org.hibernate.cfg.AnnotationConfiguration.addAnnotatedClass(AnnotationConfiguration.java:44)
at com.poss.saleswiz.ant.HibernateSchemaExporter.export(HibernateSchemaExporter.java:25)
at com.poss.saleswiz.ant.HibernateSchemaExporter.main(HibernateSchemaExporter.java:52)
Here is my class structure
base class Employee with subclass Region manager.
Here's the Employee class:
Code:
package com.poss.saleswiz.framework.businessobject;
import javax.ejb.Column;
import javax.ejb.Entity;
import javax.ejb.Id;
import javax.ejb.Inheritance;
import javax.ejb.InheritanceType;
import javax.ejb.Table;
@Entity
@Table(name = "swiz_employee")
@Inheritance(strategy = InheritanceType.JOINED)
public class Employee {
private String code;
private String firstName;
private String middleName;
private String lastName;
/**
* @return Returns the code.
*/
@Id
@Column(name = "employee_code", nullable = false)
public String getCode() {
return code;
}
/**
* @param inCode The code to set.
*/
public void setCode(String inCode) {
code = inCode;
}
/**
* @return Returns the firstName.
*/
@Column(name = "first_name", nullable = false)
public String getFirstName() {
return firstName;
}
/**
* @param inFirstName The firstName to set.
*/
public void setFirstName(String inFirstName) {
firstName = inFirstName;
}
/**
* @return Returns the lastName.
*/
@Column(name = "last_name", nullable = false)
public String getLastName() {
return lastName;
}
/**
* @param inLastName The lastName to set.
*/
public void setLastName(String inLastName) {
lastName = inLastName;
}
/**
* @return Returns the middleName.
*/
@Column(name = "middle_name")
public String getMiddleName() {
return middleName;
}
/**
* @param inMiddleName The middleName to set.
*/
public void setMiddleName(String inMiddleName) {
middleName = inMiddleName;
}
}
Here's the RegionManager class:
Code:
package com.poss.saleswiz.framework.businessobject;
import javax.ejb.CascadeType;
import javax.ejb.Column;
import javax.ejb.Entity;
import javax.ejb.GeneratorType;
import javax.ejb.Id;
import javax.ejb.Inheritance;
import javax.ejb.InheritanceJoinColumn;
import javax.ejb.InheritanceType;
import javax.ejb.JoinColumn;
import javax.ejb.ManyToOne;
import javax.ejb.Table;
@Entity
@Table(name = "swiz_region_manager")
@Inheritance(strategy = InheritanceType.JOINED)
@InheritanceJoinColumn(name = "employee_code")
public class RegionManager extends Employee {
private Integer id;
private Region region;
/**
* @return Returns the id.
*/
@Column(name = "assoc_id", nullable = false)
@Id(generate = GeneratorType.AUTO)
public Integer getId() {
return id;
}
/**
* @param inId The id to set.
*/
public void setId(Integer inId) {
id = inId;
}
/**
* @return Returns the region.
*/
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "region_id")
public Region getRegion() {
return region;
}
/**
* @param inRegion The region to set.
*/
public void setRegion(Region inRegion) {
region = inRegion;
}
}