@OneToMany と @ManyToOne の双方向の関係を持つ次の 2 つのエンティティがあります。以下に示すように結合クエリを使用して子テーブルをクエリすると、hibernate は自動的に各 MinuteData (子テーブル) の StandardDimension (親) テーブルをクエリし、遅延読み込みとしてマークされていても @ManyToOne 関係を読み込みます。これにより、DB のパフォーマンスの問題が発生しています。この問題を解決して、MinuteData ごとに標準ディメンション レコードが読み込まれないようにしてください。JPA 2.0 と hibernate-core-4.1.1.Final を使用しています。どんな助けでも大歓迎です。hibernate が StandardDimension オブジェクトをロードしないようにするにはどうすればよいですか?
@Query("SELECT md FROM StandardDimension sd ,MinuteData md where sd.dimensionAK = md.dimensionFK and sd.app = :applicationId and md.timeBucket between :startTime and :endTime ")
public List<MinuteData> findMinuteDataByTimeBucket( @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("applicationId") String applicationId);
@Entity (name="StandardDimension")
@Table (name="STANDARD_DIMENSION")
public class StandardDimension implements Serializable {
@OneToMany (targetEntity=MinuteData.class, fetch=FetchType.LAZY, mappedBy="dimensionFK", cascade=CascadeType.REMOVE)
private Set<MinuteData> muniteDateDimensionViaFK = new HashSet<MinuteData>();
}
@Entity (name="MinuteData")
@Table (name="MINUTE_DATA")
public class MinuteData implements Serializable {
........
@ManyToOne (fetch=FetchType.LAZY)
@JoinColumn(name="DIMENSION_FK", referencedColumnName = "DIMENSION_AK", nullable=false , unique=false , insertable=true, updatable=true)
private StandardDimension dimensionFK;
.........
}
Here is SQL Statement form console:
Hibernate:
select
minutedata1_.minute_data_pk as minute1_1_,
minutedata1_.created_date as created2_1_,
minutedata1_.data_obj as data3_1_,
minutedata1_.dimension_fk as dimension6_1_,
minutedata1_.modified_date as modified4_1_,
minutedata1_.time_bucket as time5_1_
from
standard_dimension standarddi0_,
minute_data minutedata1_
where
standarddi0_.dimension_ak=minutedata1_.dimension_fk
and standarddi0_.app=?
and (
minutedata1_.time_bucket between ? and ?
)
Hibernate:
select
standarddi0_.standard_dimensions_pk as standard1_2_0_,
standarddi0_.app as app2_0_,
standarddi0_.created_date as created3_2_0_,
standarddi0_.data_center as data4_2_0_,
standarddi0_.dimension_ak as dimension5_2_0_,
standarddi0_.env as env2_0_,
standarddi0_.last_seen as last7_2_0_,
standarddi0_.modified_date as modified8_2_0_,
standarddi0_.server as server2_0_,
standarddi0_.app_version as app10_2_0_
from
standard_dimension standarddi0_
where
standarddi0_.dimension_ak=?