2012-05-30 229 views

回答

0

爲我工作:

public abstract class Table { 

    private String commonField; 

    @Column(name = "COMMON_FIELD") 
    public String getCommonField() { 
     return commonField; 
    } 

    public void setCommonField(String commonField) { 
     this.commonField = commonField; 
    } 

} 

@Entity 
@Table(name = "table_a") 
public class TableA extends Table { 

    // table_a fields only 

} 

@Entity 
@Table(name = "table_b") 
public class TableB extends Table { 

    // table_b fields only 

} 
+0

要是:列名有什麼不同? – seesee

+0

你說數據庫中的* 2表與確切的[相同]列* *。如果名稱不同,則不能將它們因式分解,因爲兩列實際上並不相同。 – sp00m

+0

我今天剛測試過。由於某種原因,部分工作只是部分工作,休眠不會看抽象類來獲取字段,但只有主類。所以當你更新。抽象類將不會初始化某些反應。 – seesee