问题
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
回答1:
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
来源:https://stackoverflow.com/questions/41125387/lazytoone-and-spring-loadtimeweaver