I have the following structure:
@Entity
class Parent {
@Id
private String id;
@Embedded
private Child child;
}
@Embeddable
class Child {
@Column(...)
private int fieldA;
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(...)
private A a;
}
And A
is a plain Java class.
class A {
...
}
My question is, is it possible to lazy load the a
field of the Child class, when loading a parent object from the database ? I tried with the enhancer plugin, but the field is still eagerly fetched.
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<configuration>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
</configuration>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Lazy loading the child field of Parent class is not an option. My goal is to lazy load only the a
field of Child class. Any suggestions are welcome
It seems like this is an issue in the hibernate. Unfortunately it is still opened and maybe it will be fixed in 6.0 version according to the comments section of the issue.
Depending on your usecase, you can workaround this using a relation, or move out the fields that you need to be lazy loaded from the embeddable entity.