简体   繁体   English

JPA内部加入视图

[英]JPA INNER JOIN WITH VIEW

I have the Results JPA class containing the folowing anotation. 我有包含以下注释的Results JPA类。

@JoinColumn (name = "cod_id", insertable = false, updatable = false, referencedColumnName = "cod")
@ManyToOne(optional = true, fetch=FetchType.EAGER)
private TableView dep;

The TableView is an entity which origin is from a view from an another database. TableView是一个实体,其源于另一个数据库的视图。 So, as far as I can see, I cant access the table directly. 因此,据我所知,我无法直接访问该表。

Ok. 好。 After this introduction, here it is: 介绍之后,这里是:

The Problem: When I fetch Results, TopLink JPA queries for each dep one by one. 问题:获取结果时,TopLink JPA逐一查询每个部门。 It gets all the resultSet from Results and, then, gets each dep one by one. 它从Results中获取所有resultSet,然后逐个获取每个dep。

The Question: Is there a way to avoid this behavior? 问题:是否有避免这种行为的方法? In a way that minimize the database server effort? 以最小化数据库服务器工作量的方式?

You can use a join fetch in your query, or use @JoinFetch in the mapping, or use a batch fetch. 您可以在查询中使用联接提取,或在映射中使用@JoinFetch,或使用批提取。

See, http://java-persistence-performance.blogspot.com/2010/08/batch-fetching-optimizing-object-graph.html 参见http://java-persistence-performance.blogspot.com/2010/08/batch-fetching-optimizing-object-graph.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM