Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate - Difference between bytecode instrumentation and bytecode enhancement?

Tags:

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.

like image 617
ascott Avatar asked Oct 24 '14 15:10

ascott


People also ask

What is bytecode enhancement?

Abstract. Bytecode enhancement is the process of manipulating the bytecode (. class) representation of a class for some purpose. This chapter explores Hibernate's ability to perform bytecode enhancement.

What is bytecode instrumentation?

Bytecode instrumentation is a process where new function- ality is added to a program by modifying the bytecode of a set of classes before they are loaded by the virtual machine. This paper will look into the details of bytecode instrumen- tation in Java: the tools, APIs and real-life applications.


1 Answers

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.

like image 99
Somnath Sarode Avatar answered Oct 09 '22 07:10

Somnath Sarode