Java @embeddeble的表名

Java @embeddeble的表名,java,hibernate,jpa,orm,spring-data-jpa,Java,Hibernate,Jpa,Orm,Spring Data Jpa,我有一门课如下 @Entity @Table(name = "template") public class DynamicTemplate { @Id private Long id; @ElementCollection Set<TemplateAttributes> attributes; //setters and getters 在数据库中,正在使用模板属性创建@embeddeble表,而不是使用提供的名称

我有一门课如下

@Entity
@Table(name = "template")
public class DynamicTemplate {
    @Id
    private Long id;
 
    @ElementCollection
    Set<TemplateAttributes> attributes;

    //setters and getters

在数据库中,正在使用模板属性创建@embeddeble表,而不是使用提供的名称属性创建@embeddeble表

@Embeddeble标记此对象不映射为表,而是一组嵌入到其他实体/表中的属性(实际上,您可以将其用于不同实体的多个属性)

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


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

您的模式没有多大意义

@Embeddeble标记此对象不映射为表,而是一组嵌入到其他实体/表中的属性(实际上,您可以将其用于不同实体的多个属性)

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


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

您需要使用CollectionTable注释:

@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;

    ...
}
@实体
@表(name=“template”)
公共类DynamicTemplate{
@身份证
私人长id;
@元素集合
@CollectionTable(name=“attribute”)
设置属性;
...
}
@可嵌入
公共类模板属性{
私有字符串名称;
私人双正常值低;
...
}

您需要使用CollectionTable注释:

@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;

    ...
}
@实体
@表(name=“template”)
公共类DynamicTemplate{
@身份证
私人长id;
@元素集合
@CollectionTable(name=“attribute”)
设置属性;
...
}
@可嵌入
公共类模板属性{
私有字符串名称;
私人双正常值低;
...
}

工作正常工作正常