我有以下实体,它是应用程序中每个其他实体的基本实体:
@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;
}
我的目标是有两张桌子-
和
文件夹
因此这两个表被共享给扩展BaseEntity的所有实体。我知道所有扩展BaseEntity的实体都应该有一个共享id序列。
然后我有两个实体,它们是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;
}
现在,当我准备好的时候
spring.jpa.hibernate.ddl-auto = create-drop
,hibernate为我生成以下表格:
news, equipment, news_images, news_files, equipment_images, equipment_files
news, equipment, files, images
我真的很感谢你的帮助,
谢谢