4

I have the known problem, that Hibernate loads the data eager even with the annotation fetchtype.lazy (described for example here: http://justonjava.blogspot.de/2010/09/lazy-one-to-one-and-one-to-many.html).

So I added the annotation @LazyToOne(LazyToOneOption.NO_PROXY) to my attributes and enabled bytecode Instrumentation with springs loadtimeweaver.
But hibernate still loads my properties eagerly.

I have tested the loadtimeweaver by weaving own code and it works. Does anyone know what I miss.

The following describes the structure of my Code.

I have entities with bidertional onetoone relationships like:

@Entity
public class ParentEntity {

  @OneToOne(fetch = FetchType.LAZY)
  @LazyToOne(LazyToOneOption.NO_PROXY)
  private ChildEntityONE childentityOne;


  @OneToOne(fetch = FetchType.LAZY)
  @LazyToOne(LazyToOneOption.NO_PROXY)
  private ChildEntityTWO childentityTwo;
}

and

@Entity
public class ChildEntityONE {
  @OneToOne(fetch = FetchType.LAZY)
  @LazyToOne(LazyToOneOption.NO_PROXY)
  private ParentEntity parentEntity ;
}

@Entity
public class ChildEntityTWO {
  @OneToOne(fetch = FetchType.LAZY)
  @LazyToOne(LazyToOneOption.NO_PROXY)
  private ParentEntity parentEntity ;
}

And I enabled in my Application class loadTimeWeaving with:

@EnableLoadTimeWeaving(aspectjWeaving=EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class Application {
...
}

Version of the used frameworks:

Spring 4.2.3
Spring boot 1.3.2
Hibernate 4.3.11.Final

BenHeid
  • 214
  • 2
  • 14
  • Found this post very useful http://ankursinghal86.blogspot.com.es/2014/07/one-to-one-and-lazy-vs-eager-loading.html – kimy82 Dec 13 '16 at 16:13
  • thanks for this link. It is useful for understanding the lazy loading of hibernate, but don't solve my problem.. – BenHeid Dec 13 '16 at 17:35

1 Answers1

3

I found my mistake. I forgot to set the following property in application.properties.

spring.jpa.properties.hibernate.ejb.use_class_enhancer=true

This property enable the bytecode enhancement in hibernate

BenHeid
  • 214
  • 2
  • 14