休眠 - 字节码检测和字节码增强之间的区别? [英] Hibernate - Difference between bytecode instrumentation and bytecode enhancement?

查看:132
本文介绍了休眠 - 字节码检测和字节码增强之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Hibernate 4.2并构建时间字节码工具来解决出现在 @OneToOne 关系和 @Lob https://developer.jboss.org/wiki/SomeExplanationsOnLazyLoadingone-to-一个

你知道什么是区别:

Hibernate字节码工具:

a href =http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#performance-fetching-lazyproperties =noreferrer> 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#bytecode-enhancement

因为在休眠它是这样写的:


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


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

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



感谢您的帮助。 b $ b

解决方案

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


  1. 字节码工具:在运行时期间将字节码添加到Java类中。 ,但更多的是在Java类的加载时间。此外,您可以详细阅读这篇文章




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

    在大多数字节码增强的情况下,它们都是在编译后进行的。如果您的Hibernate字节码增强功能出现这种情况,那么是的,更改代码的明显选择是字节码检测。



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)

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 bytecode enhancement : http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch20.html#bytecode-enhancement

Because on the hibernate documentation, it is written :

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.

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.

解决方案

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.

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.

这篇关于休眠 - 字节码检测和字节码增强之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆