Hibernate实体扩展基类,为实体形成的表没有基类中的属性列

Kul*_*eep 3 java hibernate

public class BaseEntity {

  @Column
  private String author;

  public BaseEntity(String author) {
      this.author = author;
  }

  public String getAuthor() {
      return author;
  }
}

@Entity
@Table(name = "books")
public class Book extends BaseEntity {

  @Id
  @GeneratedValue(generator = "increment")
  @GenericGenerator(name = "increment", strategy = "increment")
  private long bookId;

  @Column
  private String title;

  public Book(String author, String title) {
    super(author);
    this.title = title;
  }

  public Book() {
    super("default");
  }

  public String getTitle() {
    return title;
  }
}
Run Code Online (Sandbox Code Playgroud)

我的sql表只有两列,bookId和title.我应该怎样做才能获得包括作者在内的所有三位成员的表格.

我的sql表只有两列,bookId和title.我应该怎样做才能获得包括作者在内的所有三位成员的表格.

v.l*_*nev 9

你应该添加@MappedSuperclass注释BaseEntity

@MappedSuperclass 
public class BaseEntity {

  @Column
  private String author;

  public BaseEntity(String author) {
      this.author = author;
  }

  public String getAuthor() {
      return author;
  }

}
Run Code Online (Sandbox Code Playgroud)