有没有办法为嵌入式收藏添加鉴别器?这就是我所拥有的
@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public abstract class EncounterDataInfo implements Serializable {
@Column(length = 50, nullable = false)
private String name;
@Column(length = 50, insertable = false, updatable = false)
private String type;
}
@Embeddable
@DiscriminatorValue("DIAGNOSIS")
public class Diagnosis extends EncounterDataInfo {
}
@Embeddable
@DiscriminatorValue("MODIFIER")
public class Modifier extends EncounterDataInfo {
}
@Entity
@Table(name = "ENCOUNTER_DATA")
public class EncounterData extends AuditingEntity {
@ElementCollection(targetClass = Diagnosis.class)
@CollectionTable(name = "ENCOUNTER_DATA_INFO", joinColumns = @JoinColumn(name = "encounter_data_id"))
private List<Diagnosis> diagnoses;
@ElementCollection(targetClass = Modifier.class)
@CollectionTable(name = "ENCOUNTER_DATA_INFO", joinColumns = @JoinColumn(name = "encounter_data_id"))
private List<Modifier> modifiers;
}
目前,两个字段的EncounterData实例都具有来自encounter_data_info表的所有值,而不依赖于类型。所以似乎鉴别器价值不起作用?为什么以及如何使其发挥作用?