Parent table and class
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "vehicle")
public class Vehicle extends Entity {
// Attributes
}
create table vehicle
(
id varchar2(50) not null,
// Attributes
)tablespace :TABLESPACE_DATA ;
Child 1 table and class
@Entity
@Table(name = "car")
public class Car extends Vehicle {
// Attributes
}
create table car
(
// Attributes
) inherits (vehicle) tablespace :TABLESPACE_DATA ;
Child 2 table and class
@Entity
@Table(name = "bus")
public class Bus extends Vehicle {
// Attributes
}
create table bus
(
// Attributes
) inherits (vehicle) tablespace :TABLESPACE_DATA ;
If I add a new Car, then there will be one record which can be visible from both tables (Vehicle & Car)
Then with a Hibernate generated query by id for the Vehicle (check below) it will return with two rows, which cause an exception.
select
// ...
from
(
select
id,
//
0 as clazz_
from
VEHICLE
union all
select
id,
//
1 as clazz_
from
car
union all
select
id,
//
2 as clazz_
from
bus
) vehicle0_
where
vehicle0_.id = ?
The main problem is that the Hibernate include the parent class as well. This can be resolved if the parent class is abstract. Is there any other way to avoid the union of parent?