Hi I have just started using Spring , with Hibernate4 and maven. Basically my class hierarchy is HUmanMicroTask extends from MicroTask . In future there may be several other
For TABLE_PER_CLASS hierarchy, the child class inherit the unique key from the parent and so we should not mention unique key constraint in child entity.
Remove the primary key annotations and this worked well for me.
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)
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;
}
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
It is due to Id column in both classes. Remove the Id from HumanMicroTask.