Versiones comparadas

Clave

  • Se ha añadido esta línea.
  • Se ha eliminado esta línea.
  • El formato se ha cambiado.

Para poder inicializar atributos de manera lazy con Hibernate, debemos permitir el byte code enhancement, añadiendo .

Para revisar que se está haciendo, hay que comprobar que en nuestro pom.xml se encuentra el siguiente plugin a nuestro pom.xml:

Bloque de código
languagexml
<plugin>
  <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>
        <enableDirtyTracking>true</enableDirtyTracking>
        <enableAssociationManagement>true</enableAssociationManagement>
        <enableExtendedEnhancement>false</enableExtendedEnhancement>
      </configuration>
      <goals>
        <goal>enhance</goal>
      </goals>
    </execution>
  </executions>
</plugin>


Además, en application.properties hay properties comprobar que añadir existe la siguiente línea y añadirla en caso de no estar:

Bloque de código
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true

...