仅在查询子类时如何在JPA中省略超类的加入?

时间:2018-08-27 13:25:49

标签: java hibernate jpa inheritance optimization

我有一个具有类层次结构的JPA模型。我使用InheritanceType.JOINED策略。我的模特:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class A {

    @Id
    @GeneratedValue
    private Long id;

    public Long getId() {
        return id;
    }

}

@Entity
public class SubA extends A {

    private String val;

    public String getVal() {
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }

}

JPA查询

select val from SubA

生成此sql

select suba0_.val as col_0_0_ from SubA suba0_ inner join A suba0_1_ on suba0_.id=suba0_1_.id

超类表有一个内部联接,这是没有用的。我什么都不需要。有办法避免这种情况吗?谢谢!

(带有Hibernate 5.2.15.Final的testet)

0 个答案:

没有答案