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 
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With