I have a class and subclasses who extends that.
Like this:
@Table
@Entity
class Cat{
class DomesticCat extends Cat{
LitterBox litterBox;
//getter and setters
}
class TigerCat extends Cat{
HuntingStyle huntingStyle;
//getter and setters
}
}
I want to query with hql.
For example i want to find the cat who has “blue” colored LitterBox
should i add @entity and @Table annotations before DomesticCat and TigerCat classes?
There is no column in database for subclass specific fields like litterBox and huntingStyle.
Thanks
@Entity needs to be added for
DomesticCatandTigerCatif you want to persist them. You can use the @Inheritance annotation for defining how the subclasses should be mapped – for a single table, use@Inheritance(strategy=SINGLE_TABLE).@Table will be defaulted if you don’t add it.