@Basic(fetch = FetchType.LAZY) does not work?
hibernate, java, jpa, lazy-loading, orm
Solution
First of all, you should know that the JPA specs clearly specifies that LAZY is only a hint to JPA providers, so it's not a mandatory requirement.
For basic type lazy fetching to work, you need to enable bytecode enhancement and explicitly set the `enableLazyInitialization` configuration property to `true`:
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<configuration>
<enableLazyInitialization>true</enableLazyInitialization>
</configuration>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Problem
I use JPA (Hibernate) with Spring. When I want to lazy load a String property, i use this syntax: ``` @Lob @Basic(fetch = FetchType.LAZY) public String getHtmlSummary() { return htmlSummary; } ``` But when I look at the sql that hibernate creates, it seems this property is not lazy loaded? I also use this class `org.hibernate.tool.instrument.javassist.InstrumentTask` in ANT script to instrument this property but it seems it does not work.