我有一個用戶類,它是一個晚餐類,一個學生類是用戶的子類。我的代碼沒有錯誤,但我不知道為什么當我洗掉“擴展用戶”它創建表時它不會在資料庫中創建表?
這是我的代碼
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
public abstract class User {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
private String username;
private String email;
private String password;
@Enumerated(EnumType.STRING)
@Column(length = 20)
private Role name;
}
@Entity
@Table(name = "student")
@Data
public class Student extends User{
@Id
private Long id;
private LocalDate dob;
private String tell;
private String course;
}
uj5u.com熱心網友回復:
在此鏈接中,您可以概述以下繼承方法:
MappedSuperclass- 父類,不能是物體Single Table- 來自不同類的具有共同祖先的物體被放置在一個表中。Joined Table- 每個類都有自己的表,查詢子類物體需要加入表。Table per Class- 一個類的所有屬性都在它的表中,所以不需要連接。
問候
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/498180.html
下一篇:HibernateSearch6BooleanPredicateClausesStep中的BooleanJunction#isEmpty等效項
