0
我有一個類和擴展它的子類。 像這樣:子類和hql
@Table
@Entity
class Cat{
class DomesticCat extends Cat{
LitterBox litterBox;
//getter and setters
}
class TigerCat extends Cat{
HuntingStyle huntingStyle;
//getter and setters
}
}
我想用hql進行查詢。
例如,我想找到誰擁有「藍」色的兔子廁所貓
我應該爲DomesticCat和TIGERCAT類前添加@Entity和@Table註解?
對於像litterBox和huntingStyle這樣的子類特定字段,數據庫中沒有列。
感謝
非常感謝您的回答。我應該在哪裏寫@Inheritance(strategy = SINGLE_TABLE)到父類或每個子類。並且我理解是否正確,如果我寫這個所有類都可以映射到一個表,對嗎? – merveotesi 2012-02-14 14:09:08
您應該將@Inheritance(strategy = SINGLE_TABLE)添加到父類。它的所有子類都將被映射到父類的表中。 – Pimgd 2012-02-14 14:13:12
非常感謝 – merveotesi 2012-02-14 14:20:13