Spring 3.1 Hibernate 4 exception for Inheritance [cannot be cast to org.hibernate.mapping.RootClass]
It is due to Id column in both classes. Remove the Id from HumanMicroTask.
to fix this Remove @Id from Subclass
in MicroTask keep
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "MICROTASKID")
private String microTaskId;
in Subclass HumanMicroTask remove
@Id
@Column(name = "HMTID")
private String humanMicroTaskid;
I had the same problem some time ago, since your parent class has a primary key: 'Id', when the subclasses are generated they automatically generate a foreign key with the exact name of their parent's primary key
Example: (Pseudocode)
Entity Definition
Parent Class
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "abstract_person", catalog = "catalog", schema = "")
class AbstractPerson{
//Primary Key
@Id
@Column(name = "idPerson")
int idPerson;
@Basic
@Column(name = "name")
String name;
//corresponding getters and setters
}
Child Class:
@Entity
@Table(name = "concrete_person", catalog = "catalog", schema = "")
class ConcretePerson extends AbstractPerson{
//No id or primary key is defined here
@Basic
@Column(name="profession")
String profession;
}
Table Generation
Parent class will map to this
Table "abstract_person"
id: Int (primary key)
name: Varchar
Child class will map to this:
Table "concrete_person"
profession: Varchar
idPerson: int (Automatically generated, foreign key to parent table and primary
class of this table)
//Assumptions
Mysql database;
Jpa 2 Hibernate Implementation;
NetBeans 7x Ide