LazyToOne和Spring LoadTimeWeaver [英] LazyToOne and Spring LoadTimeWeaver
问题描述
我有一个已知的问题,即使使用注释fetchtype.lazy(例如,在此处进行描述:
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).
因此我在属性中添加了注释@LazyToOne(LazyToOneOption.NO_PROXY)
,并使用springs loadtimeweaver启用了字节码检测.
但是hibernate仍然热切地加载我的属性.
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.
我已经通过编织自己的代码对loadtimeweaver进行了测试,并且可以正常工作.有谁知道我想念的东西.
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;
}
和
@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 ;
}
然后在我的Application类loadTimeWeaving中启用了
And I enabled in my Application class loadTimeWeaving with:
@EnableLoadTimeWeaving(aspectjWeaving=EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class Application {
...
}
所用框架的版本:
春季4.2.3
春季靴1.3.2
Hibernate 4.3.11.Final
Spring 4.2.3
Spring boot 1.3.2
Hibernate 4.3.11.Final
推荐答案
我发现了我的错误.我忘了在application.properties中设置以下属性.
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
这篇关于LazyToOne和Spring LoadTimeWeaver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!