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

My sql table have just two columns, bookId and title. What should I do to get table for all the three members including author.

My sql table have just two columns, bookId and title. What should I do to get table for all the three members including author.

1 Answer 1

10

You should add @MappedSuperclass annotation to the BaseEntity

@MappedSuperclass 
public class BaseEntity {

  @Column
  private String author;

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

  public String getAuthor() {
      return author;
  }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.