数据库视图hibernate映射

时间:2017-12-05 04:02:25

标签: java database hibernate jpa

我正在使用数据库视图(view1)的Hibernate映射,它包含另一个视图(view2)。它有效,但我收到了很多数据库的请求,我想优化它。有什么问题?

@Entity
@Table(name = "view1")
public class View1 {

    @Id
    @Column(name = "id")
    private Long id;
    @JoinColumn(name = "id", referencedColumnName = "operation", insertable = false, updatable = false)
    @ManyToOne(fetch = FetchType.LAZY)
    private View2 view2;
...
}

@Entity
@Table(name = "view2")
public class View2 {

    @Id
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @Column(name = "operation")
    private Long operation;
...
}

下一个JPQL查询会产生太多请求。

select e from View1 e left join fetch e.view2

生成的本机SQL,重复60次以上

select view20_.id as id1_221_0_, view20_.operation as operati16_221_0_

0 个答案:

没有答案