Hibernate Lazy Loading Single Column

时间:2018-06-12 20:34:28

标签: java spring hibernate lazy-loading load-time-weaving

在Tomcat和Hibernate 5.0中使用Spring运行

尝试延迟加载单个列,如果没有字节码增强,似乎不支持。我已尝试执行these步骤,但该列仍在作为初始查询加载。

@Bean( JpaConfig.EMF )
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
final DataSource dataSource,
final JpaVendorAdapter jpaVendorAdapter )
....
props.put( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION, Boolean.toString( true ) );
emf.setJpaPropertyMap( props );

列配置

@Column( name = "file_data", nullable = false )
@Basic( fetch = FetchType.LAZY )
    private byte[] fileData;

Spring配置类

@Configuration
@EnableLoadTimeWeaving

启动输出

[INFO ] [17:22:56] [localhost-startStop-1] weaving.DefaultContextLoadTimeWeaver:76 - Determined server-specific load-time weaver: org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver
Jun 12, 2018 5:22:56 PM org.apache.catalina.loader.WebappClassLoaderBase addTransformer
INFO: Added class file transformer [org.springframework.context.weaving.AspectJWeavingEnabler$AspectJClassBypassingClassFileTransformer@6086a542] to web application [ROOT].
[INFO ] [17:22:56] [localhost-startStop-1] weaving.DefaultContextLoadTimeWeaver:76 - Determined server-specific load-time weaver: org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver
[INFO ] [17:27:05] [localhost-startStop-1] jpa.LocalContainerEntityManagerFactoryBean:356 - Building JPA container EntityManagerFactory for persistence unit 'persistenceUnit'
Jun 12, 2018 5:27:20 PM org.apache.catalina.loader.WebappClassLoaderBase addTransformer
INFO: Added class file transformer [Standard ClassFileTransformer wrapping JPA transformer: org.hibernate.jpa.internal.enhance.EnhancingClassTransformerImpl@20635e8] to web application [ROOT].

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

根据JPA规范,延迟加载的指令只是对你的情况下持久性提供程序Hibernate的一个提示。提供者可能不尊重您的提示。 一般来说,你的目标是什么?由于没有涉及对象图,因此在获取基本类型的其他字段时不会松懈。 如果您有大型数组,请添加@Lob注释。