我有一节课如下
@Entity
@Table(name = "template")
public class DynamicTemplate {
@Id
private Long id;
@ElementCollection
Set<TemplateAttributes> attributes;
//setters and getters另一张桌子如下所示
@Table(name = "attribute")
@Embeddable
public class TemplateAttributes {
private String name;
private Double normalLow;在数据库中,@Embeddable表是用template_attributes名称创建的,而不是提供名称属性的
发布于 2021-01-15 13:47:20
您需要使用集合表-注释:
@Entity
@Table(name = "template")
public class DynamicTemplate {
@Id
private Long id;
@ElementCollection
@CollectionTable(name = "attribute")
Set<TemplateAttributes> attributes;
...
}
@Embeddable
public class TemplateAttributes {
private String name;
private Double normalLow;
...
}发布于 2021-01-15 11:21:18
您的模式没有多大意义。
@Embeddable标记该对象不是要映射为表,而是一组嵌入/嵌入到另一个实体/表中的属性(实际上,您可以在不同实体中对多个属性使用它)。
如果DynamicTemplate具有TemplateAttributes属性;属性,则表模板中将有name和normalLow列。但是,不能将一组值作为同一表中的列。
您需要的是使TemplateAttributes成为一个实体,或者,如果您需要重用TemplateAttributes,则创建一个新的实体,该实体具有一个id和一个TemplateAttributes属性,并拥有一组它们。
https://stackoverflow.com/questions/65735079
复制相似问题