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 two records with same id, one in a parent table, other in a child table.
Then with a Hibernate generated query (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 = '5105f2d9-9c69-44c1-9368-0b3013a3a058'
The Hibernate version 5.4.28.
What could be the issue?