Hibernate批量提取到延迟加载

ili*_*den 4 hibernate lazy-loading

目前,我在hbernate3中观察到以下行为.如果我设置了@BatchSize(size = 5),那么hibernate将在一个SQL查询中获取映射类型的5个子集.

如果我有.setFetchMode("set",FetchMode.JOIN); 然后,hibernate会急切地在单个SQL查询中获取映射类型的所有子集.

但是,当我设置.setFetchMode("commands",FetchMode.SELECT); ,然后hibernate仍然使用批量提取,而不是延迟提取.

有没有办法强制hibernate在设置@BatchSize时使用延迟抓取?

同样的问题适用于设置@Fetch(FetchMode.SUBSELECT)的时间.

use*_*943 7

如果要以编程方式覆盖这些设置,可以考虑使用@FetchProfile.只需为实体创建一个@FetchProfile:

@FetchProfiles({
  @FetchProfile(name = "profileName", fetchOverrides = {
    @FetchProfile.FetchOverride(entity = YourEntity.class, 
                                association = "anAssociation", 
                                mode = FetchMode.JOIN),
...
}) })
并在您的服务/存储库方法中启用该配置文件,如:

session.enableFetchProfile( "profileName" );
并且您的自定义提取设置将适用于该会话.