@DiscriminatorFormula - 冗余IN限制

时间:2012-11-02 04:38:48

标签: java hibernate hibernate-mapping

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

当我使用HQL查询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 = "";
}

0 个答案:

没有答案