Reputation: 191
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.
Upvotes: 3
Views: 3538
Reputation: 19956
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;
}
}
Upvotes: 10