You're trying to map the association to the class that is not entity (
AbstractShape), i.e.
@MappedSuperclass presence doesn't imply that the marked class is entity. If you still want to use a
'table-per-concrete-class' strategy just switch to the
'Table per concrete class with unions' variation:
AbstractShape
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractShape {
private Long id;
private String shapeField;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column
public String getShapeField() {
return shapeField;
}
public void setShapeField(String shapeField) {
this.shapeField = shapeField;
}
}
RectangleCode:
@Entity
public class Rectangle extends AbstractShape {
private String rectangleField;
@Column
public String getRectangleField() {
return rectangleField;
}
public void setRectangleField(String rectangleField) {
this.rectangleField = rectangleField;
}
}
CircleCode:
@Entity
public class Circle extends AbstractShape {
private String circleField;
@Column
public String getCircleField() {
return circleField;
}
public void setCircleField(String circleField) {
this.circleField = circleField;
}
}
The most important point here is a key generation strategy for the
AbstractShape class - the key must be unique for all three tables (for the
AbstractShape,
Rectangle and
Circle). The best decision is to use sequence-based generation strategy if your database supports it. Given
'table' strategy is used just for the presentation purposes.