首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@Embeddable表名

@Embeddable表名
EN

Stack Overflow用户
提问于 2021-01-15 11:12:18
回答 2查看 636关注 0票数 0

我有一节课如下

代码语言:javascript
复制
@Entity
@Table(name = "template")
public class DynamicTemplate {
    @Id
    private Long id;
 
    @ElementCollection
    Set<TemplateAttributes> attributes;

    //setters and getters

另一张桌子如下所示

代码语言:javascript
复制
@Table(name = "attribute")
@Embeddable
public class TemplateAttributes {
    private String name;
    private Double normalLow;

在数据库中,@Embeddable表是用template_attributes名称创建的,而不是提供名称属性

EN

回答 2

Stack Overflow用户

发布于 2021-01-15 13:47:20

您需要使用集合表-注释:

代码语言:javascript
复制
@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;

    ...
}
票数 2
EN

Stack Overflow用户

发布于 2021-01-15 11:21:18

您的模式没有多大意义。

@Embeddable标记该对象不是要映射为表,而是一组嵌入/嵌入到另一个实体/表中的属性(实际上,您可以在不同实体中对多个属性使用它)。

如果DynamicTemplate具有TemplateAttributes属性;属性,则表模板中将有name和normalLow列。但是,不能将一组值作为同一表中的列。

您需要的是使TemplateAttributes成为一个实体,或者,如果您需要重用TemplateAttributes,则创建一个新的实体,该实体具有一个id和一个TemplateAttributes属性,并拥有一组它们。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65735079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档