如何从具有生成的 Id 的抽象类创建子类?

huangapple 未分类评论42阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年4月4日 21:26:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/61028780.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定