我有一个问题,我有一个带有继承 TABLE_PER_CLASS 和三个子表 StationCompany StationAnalysis StationVariant 的基本抽象实体站
@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS )
public abstract class Station {
@Entity
public class StationCompany extends Station {
@ManyToOne(optional = false, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
private Company company;
@Entity
public class StationAnalysis extends StationCompany {
@ManyToOne(optional = false, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
private Analysis analysis;
@Entity
public class StationVariant extends StationAnalysis {
@ManyToOne(optional = false, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
private Variant variant;
public interface IStationCompanyRepository extends JpaRepository<StationCompany, Long> {
@Service
public class StationService implements IStationService<StationCompany> {
@Autowired
IStationCompanyRepository stationCompanyRepository;
然后我在 StationCompany 上搜索 findAll,hibernate 使用 union select 进行查询。我将只搜索 StationCompany 条目。
select x from ( select a from StationCompany union select b from StationVariant union select c from StationAnalysis )