Hibernate - 字节码检测和字节码增强之间的区别?

时间:2022-12-21 08:15:20

I am using Hibernate 4.2 and build time bytecode instrumentation for solve the lazy issue that appears on a @OneToOne relation and @Lob (https://developer.jboss.org/wiki/SomeExplanationsOnLazyLoadingone-to-one)

我正在使用Hibernate 4.2和构建时间字节码检测来解决@OneToOne关系和@Lob上出现的懒惰问题(https://developer.jboss.org/wiki/SomeExplanationsOnLazyLoadingone-to-one)

Do you know what is the difference between :

你知道之间有什么区别:

Hibernate bytecode instrumentation : http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#performance-fetching-lazyproperties

Hibernate字节码检测:http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#performance-fetching-lazyproperties

Hibernate bytecode enhancement : http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#bytecode-enhancement

Hibernate字节码增强:http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#bytecode-enhancement

Because on the hibernate documentation, it is written :

因为在hibernate文档中,它写成:

The EnhancementTask is intended as a total replacement for InstrumentTask. Further, it is also incompatible with InstrumentTask, so any existing instrumented classes will need to be built from source again.

EnhancementTask旨在作为InstrumentTask的完全替代品。此外,它也与InstrumentTask不兼容,因此需要再次从源构建任何现有的检测类。

I can solve my issue by using bytecode instrumentation but it doesn't works by using bytecode enhancement. Do you know why ?

我可以通过使用字节码检测来解决我的问题,但它不能通过使用字节码增强来工作。你知道为什么吗 ?

Maybe, this new feature is not fully developped ?

也许,这个新功能还没有完全开发出来?

Thanks for your helps.

谢谢你的帮助。

1 个解决方案

#1


5  

The answer is the way byte code enhancement is done. Let's see what happen in both cases

答案是字节码增强的方式。让我们看看两种情况都会发生什么

  1. Bytecode instrumentation: Adding bytecode to a Java class during “run time.” It's not really during run time, but more during “load” time of the Java class. Further you can read this post in detail.
  2. 字节码检测:在“运行时”期间将字节码添加到Java类。它不是在运行时,而是在Java类的“加载”时间内更多。此外,您可以详细阅读这篇文章。

And

  1. Bytecode enhancement: Bytecode enhancement may be performed either at runtime or at build time (offline). When enhancement is performed at runtime, persistent classes are enhanced as they are loaded. When enhancement is performed offline, class files are enhanced during a post-compilation step;

    字节码增强:可以在运行时或构建时(离线)执行字节码增强。在运行时执行增强时,持久类在加载时会得到增强。离线执行增强时,在编译后步骤中增强类文件;

    In most case of bytecode enhancement, they are done at post compilation. If this is the case with your Hibernate bytecode enhancement, then yes the obvious choice to change the code is the byte code instrumentation.

    在大多数字节码增强的情况下,它们是在后编译时完成的。如果您的Hibernate字节码增强就是这种情况,那么更改代码的明显选择是字节码检测。

#1


5  

The answer is the way byte code enhancement is done. Let's see what happen in both cases

答案是字节码增强的方式。让我们看看两种情况都会发生什么

  1. Bytecode instrumentation: Adding bytecode to a Java class during “run time.” It's not really during run time, but more during “load” time of the Java class. Further you can read this post in detail.
  2. 字节码检测:在“运行时”期间将字节码添加到Java类。它不是在运行时,而是在Java类的“加载”时间内更多。此外,您可以详细阅读这篇文章。

And

  1. Bytecode enhancement: Bytecode enhancement may be performed either at runtime or at build time (offline). When enhancement is performed at runtime, persistent classes are enhanced as they are loaded. When enhancement is performed offline, class files are enhanced during a post-compilation step;

    字节码增强:可以在运行时或构建时(离线)执行字节码增强。在运行时执行增强时,持久类在加载时会得到增强。离线执行增强时,在编译后步骤中增强类文件;

    In most case of bytecode enhancement, they are done at post compilation. If this is the case with your Hibernate bytecode enhancement, then yes the obvious choice to change the code is the byte code instrumentation.

    在大多数字节码增强的情况下,它们是在后编译时完成的。如果您的Hibernate字节码增强就是这种情况,那么更改代码的明显选择是字节码检测。