[英]Hibernate - @OneToMany in @MappedSuperclass generates table for every child entity
I have the following entity which is a base entity for every other entity in the app: 我有以下实体,它是应用程序中所有其他实体的基础实体:
@Audited
@Data
@MappedSuperclass
public abstract class BaseEntity {
public static final long UNSAVED = 0;
@Id
@GeneratedValue
private long id;
@OneToMany(cascade = CascadeType.ALL)
private List<Image> images;
@OneToMany(cascade = CascadeType.ALL)
private List<File> files;
}
My goal is to have two tables - images and files so that these two tables are shared to all entities that extend BaseEntity. 我的目标是拥有两个表- 图像和文件,以便将这两个表共享给所有扩展BaseEntity的实体。 I do realize that for that all entities that extend BaseEntity should have one shared id sequence.
我确实意识到,所有扩展BaseEntity的实体都应具有一个共享的ID序列。
And then I have two entities that are subtypes of the BaseEntity: 然后,我有两个实体,它们是BaseEntity的子类型:
@Entity
@Table
@Data
@EqualsAndHashCode(callSuper = false)
public class Equipment extends BaseEntity {
private String name;
@Enumerated(EnumType.STRING)
private EquipmentType type;
private String model;
private String serial;
private Boolean status;
}
@Entity
@Table
@Data
@EqualsAndHashCode(callSuper = false)
public class News extends BaseEntity {
private String title;
private String summary;
private String content;
}
Now, when I set spring.jpa.hibernate.ddl-auto = create-drop
, hibernate generates the following tables for me: 现在,当我设置
spring.jpa.hibernate.ddl-auto = create-drop
,hibernate会为我生成以下表:
news, equipment, news_images, news_files, equipment_images, equipment_files
However, I would like to have four tables instead: 但是,我想有四个表:
news, equipment, files, images
I would really appreciate any help, 我真的很感谢您的帮助,
Thanks 谢谢
Try adding to the @OneToMany
lists a @JoinColumn(name="ID_SOMETHING")
. 尝试将添加到
@OneToMany
列表中的@JoinColumn(name="ID_SOMETHING")
。 These two part column names news_images
are join tables created by Hibernate if no @JoinColumn
is specified. 如果未指定
@JoinColumn
则这两部分列名称news_images
是Hibernate创建的news_images
表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.