LazyToOne and Spring LoadTimeWeaver

回眸只為那壹抹淺笑 提交于 2020-01-13 14:44:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!