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