英文:
How can I create a subclass from an abstract class having a generated Id?
问题
以下是翻译好的内容:
我创建了一个超类(Account)。我创建了一个生成的 Id 属性。子类(MainAccount)从 Account 继承。当我从子类创建一个实例时,对象的 Id 为 null。我不明白为什么它没有被生成。
这是我的抽象超类:Account
@Data
@MappedSuperclass
public abstract class Account {
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
protected String id;
protected double balance;
}
这是子类的代码:MainAccount
@Setter
@Getter
@Entity
@Table(name = "main_account")
public class MainAccount extends Account {
private String enumber;
}
英文:
I create a superclass (Account).I create a generated Id attribute .the subclass ( Main account)extend from Account.When I createn instance from the subclass , the Id of the object is null . I don't understand why it is not generated .
Here is my abstract superclass : Account
@Data
@MappedSuperclass
public abstract class Account {
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
protected String id;
protected double balance ;
}
This is the code of the subclass : MainAccount
@Setter
@Getter
@Entity
@Table(name = "main_account")
public class MainAccount extends Account{
private String enumber ;
}
专注分享java语言的经验与见解,让所有开发者获益!
评论