Hibernate: Single table inheritance annotations

July 19th, 2009 by jeremychone
@Entity
@Table(name = "employee")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ctype", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue("e")
@ForceDiscriminator //optional
public class Employee{
...
}

And the subclass would be like

@Entity
@DiscriminatorValue("m")
public class Manager extends Employee{
....
}

One Response to “Hibernate: Single table inheritance annotations”

  1. Erik Stockton Says:

    Annotate the “ctype” field in the superclass with: @Column(insertable=false, updatable=false) to fix this problem.

Leave a Reply