0

我有类的层次结构,例如 AbstractClass - Employee - Engineer (以及许多其他子类),并且我使用每个类层次结构策略的单个表。AbstractClass 有属性case,在我定义的 Employee 中@DiscriminatorFormula("case"),Engineer 有一些@DiscriminatorValue

当我使用 HQL-query 加载所有对象时SELECT id FROM Employee,Hibernate 会进行此 SQL 查询:

select employee0_.id as col_0_0_ from public.tbl_employee employee0_ where employee0_.case in ('engineer', 'operator')

换句话说,Hibernate 添加了带有所有鉴别器值的冗余限制。

有没有办法从 SQL 中排除这个 IN 限制?


AbstractClass 和 Employee 有一些简化的映射:

@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractClass {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN")
    @SequenceGenerator(name = "SEQ_GEN", sequenceName = "objectid_sequence", allocationSize = 100)
    private long id;

    @Column(name = "case", nullable = false)
    private String case;
}

@Entity
@Table(name = "tbl_employee")
@DiscriminatorFormula("case")
public class Employee extends AbstractClass {

    @Column(name = "name", nullable = false)
    private String name = "";
}
4

0 回答 0