忽略@MappedSuperclass而不是扩展类JPA

问题描述 投票:0回答:1

例如,我有两个类FullTimeEmployee和PartTimeEmployee。 FullTimeEmployee必须扩展Employee表并使用@MappedSuperclass访问该属性,但PartTimeEmployee类不需要任何扩展,但如果不扩展所有其他类,则抛出JPA错误。

@MappedSuperclass
public class Employee {
      @Id
      @GeneratedValue
      private long id;
      private String name;
        .............
}

@Entity
public class FullTimeEmployee extends Employee {
  private int salary;
    .............
}

我不希望使用员工@MappedSuperclass扩展PartTimeEmployee类不允许我这样做

@Entity
public class PartTimeEmployee {
  private int hourlyRate;
    .............
}
java hibernate jpa spring-data-jpa persistence
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.