Hi. I needed to map 4 classes into 3 tables.
Tables:
DATA_TYPE
id number;
name varchar2;
supertype_id number;
OBJECT_TYPE
type_id number (foreign key to DATA_TYPE.id)
desc varchar2;
PROP
id number;
obj_type_id number (foreign key to OBJECT_TYPE.type_id)
name varchar2;
Classes:
@Entity
@Table(name = "DATA_TYPE")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "supertype_id")
public abstract class DataType {
private Long id;
private String name;
@Id
@Column(name = "ID")
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
@DiscriminatorValue("2")
public class SimpleType extends DataType {
}
@Entity
@DiscriminatorValue("8")
@Table(name = "OBJ_TYPE")
@PrimaryKeyJoinColumn(name = "TYPE_ID")
public class ObjectType extends DataType {
private String description;
private List<Prop> properties;
@Column(name = "desc", table = "OBJ_TYPE")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@OneToMany(mappedBy = "objectType", cascade = CascadeType.ALL, orphanRemoval = true)
public List<Prop> getProperties() {
return properties;
}
public void setProperties(List<Prop> properties) {
this.properties = properties;
}
}
@Entity
@Table(name = "PROP")
public class Prop {
private Long id;
private String name;
private ObjectType objectType;
@Id
@Column(name = "ID")
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@JoinColumn(name = "OBJ_TYPE_ID",
referencedColumnName = "TYPE_ID",
foreignKey = @ForeignKey(
name = "PROP_OBJ_FK",
value = ConstraintMode.CONSTRAINT
))
@ManyToOne(targetEntity = ObjectType.class)
public ObjectType getObjectType() {
return objectType;
}
public void setObjectType(ObjectType objectType) {
this.objectType = objectType;
}
}
But when i tried to setup this configuration, it breaks, because it could not find table for SimpleType. Is it possible to avoid it?