2016-02-02 26 views
2
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; 
    } 
} 

我的sql表只有兩列,bookId和title。我應該做些什麼來讓包括作者在內的所有三位成員獲得表格。Hibernate實體擴展基類,爲實體形成的表沒有基類中的屬性列

我的sql表只有兩列,bookId和title。我應該做些什麼來讓包括作者在內的所有三位成員獲得表格。

回答

7

您應該添加註釋@MappedSuperclassBaseEntity

@MappedSuperclass 
public class BaseEntity { 

    @Column 
    private String author; 

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

    public String getAuthor() { 
     return author; 
    } 

}